summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs13
-rw-r--r--src/tests/errors.rs2
-rw-r--r--src/tests/locations.rs2
3 files changed, 13 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f75389b..16c16ea 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -398,7 +398,8 @@ struct Parser {
impl Parser {
fn check_valid_key(&mut self, location: &Location, s: &str) {
- if s.starts_with('.')
+ if s.is_empty()
+ || s.starts_with('.')
|| s.ends_with('.')
|| s.contains("..")
|| !s.bytes().all(|c| {
@@ -449,6 +450,10 @@ impl Parser {
if char_code == 0 {
self.nonfatal_errors.push(Error::InvalidValue(location()));
}
+ if char_code >= 0x80 {
+ self.nonfatal_errors
+ .push(invalid_escape(format!("\\x{c1}{c2}")));
+ }
value.push(char::try_from(char_code).unwrap());
}
'u' => {
@@ -574,13 +579,17 @@ impl Parser {
continue;
}
if line.starts_with('[') {
+ // [section.header]
line = line.trim_end_matches(['\t', ' ']);
if !line.ends_with(']') {
return Err(Error::UnmatchedLeftBrace(location));
}
current_section = line[1..line.len() - 1].into();
- self.check_valid_key(&location, &current_section);
+ if !current_section.is_empty() {
+ self.check_valid_key(&location, &current_section);
+ }
} else {
+ // key = value
let (mut relative_key, mut value) = line
.split_once('=')
.ok_or_else(|| Error::InvalidLine(location.clone()))?;
diff --git a/src/tests/errors.rs b/src/tests/errors.rs
index abe1bbb..b9c1da9 100644
--- a/src/tests/errors.rs
+++ b/src/tests/errors.rs
@@ -1,7 +1,7 @@
use crate::Configuration;
#[test]
-fn parsing() {
+fn errors() {
super::do_tests_in_dir("errors", ".pom", |filename| {
if Configuration::load_path(filename).is_ok() {
Err(format!("should produce an error, but doesn't").into())
diff --git a/src/tests/locations.rs b/src/tests/locations.rs
index 2310101..fdbfa2b 100644
--- a/src/tests/locations.rs
+++ b/src/tests/locations.rs
@@ -1,7 +1,7 @@
use crate::Configuration;
#[test]
-fn parsing() {
+fn locations() {
super::do_tests_in_dir("location", ".locations.pom", |filename| {
let locations = Configuration::load_path(filename)?;
let config = Configuration::load_path(&filename.replace(".locations.pom", ".pom"))?;