diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 692502e..0a966b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,10 +30,15 @@ jobs: uses: actions-rs/cargo@v1 with: command: build - - name: Unit Tests + - name: Unit Tests (default features) uses: actions-rs/cargo@v1 with: command: test + - name: "Unit Tests (all features)" + uses: actions-rs/cargo@v1 + with: + command: test + args: "--all-features" quality: name: Code Quality runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index 8d2b46e..50f84c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,11 @@ edition = "2021" authors = ["TheDaemoness"] include = ["/src", "/README.md", "/DOC.md"] -rust-version = "1.56" # 2021 edition +rust-version = "1.56" # 2021 edition version = "1.0.2" [workspace] members = ["tools"] + +[features] +allow-empty-values = [] diff --git a/src/linereader.rs b/src/linereader.rs index bc2604b..50c8ed8 100644 --- a/src/linereader.rs +++ b/src/linereader.rs @@ -48,10 +48,19 @@ pub fn parse_line(line: &str) -> LineReadResult<'_> { } else if let Some((key_raw, val_raw)) = l.split_once('=') { let key = key_raw.trim_end(); let val = val_raw.trim_start(); - if key.is_empty() || val.is_empty() { - Err(ParseError::InvalidLine) - } else { - Ok(Line::Pair(key.trim_end(), val.trim_start())) + match (key.is_empty(), val.is_empty()) { + (true, _) => Err(ParseError::InvalidLine), + (false, true) => { + #[cfg(feature = "allow-empty-values")] + { + Ok(Line::Pair(key.trim_end(), val)) + } + #[cfg(not(feature = "allow-empty-values"))] + { + Err(ParseError::InvalidLine) + } + } + (false, false) => Ok(Line::Pair(key.trim_end(), val.trim_start())), } } else { Err(ParseError::InvalidLine) diff --git a/src/tests/linereader.rs b/src/tests/linereader.rs index de244fe..f615699 100644 --- a/src/tests/linereader.rs +++ b/src/tests/linereader.rs @@ -19,6 +19,10 @@ fn valid_props() { (" foo = bar = baz ", Pair("foo", "bar = baz")), ("foo = bar #baz", Pair("foo", "bar #baz")), ("foo = [bar]", Pair("foo", "[bar]")), + #[cfg(feature = "allow-empty-values")] + ("foo =", Pair("foo", "")), + #[cfg(feature = "allow-empty-values")] + ("foo = ", Pair("foo", "")), ]) } @@ -64,8 +68,9 @@ fn invalid() { "][", "nonproperty", "=", - "noval = ", " = nokey", + #[cfg(not(feature = "allow-empty-values"))] + "noval = ", ]; for line in lines { assert!(matches!(