aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs15
-rw-r--r--test_data/sentences.txt5
2 files changed, 11 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index 74cb73d..14ff4eb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,6 +25,7 @@ enum Error {
DuplicateCategory(OsString),
BadPath(PathBuf),
EmptyOption,
+ InvalidLiteral(String),
}
impl fmt::Display for Error {
@@ -54,6 +55,8 @@ impl fmt::Display for Error {
write!(f, "failed to parse path: {:?}", p),
Error::EmptyOption =>
write!(f, "multi-option variable had an empty option"),
+ Error::InvalidLiteral(s) =>
+ write!(f, "literal option contains an inner quote-mark: {}", s),
}
}
}
@@ -100,13 +103,11 @@ impl DropIn {
return Ok(DropIn::OneOf(options))
}
- // TODO: investigate viability of supporting escape sequences
- if let Some(inner) = text.strip_prefix('"')
- .and_then(|s| s.strip_suffix('"'))
- {
- // REVIEW: investigate interactions of filenames that contain '"'
- if !inner.contains('"') {
- return Ok(DropIn::Literal(inner.to_string()));
+ if let Some(lit) = text.strip_prefix('"') {
+ if lit.contains('"') {
+ return Err(Error::InvalidLiteral(text.to_string()));
+ } else {
+ return Ok(DropIn::Literal(lit.to_string()));
}
}
diff --git a/test_data/sentences.txt b/test_data/sentences.txt
index 7c48dbf..e7efa26 100644
--- a/test_data/sentences.txt
+++ b/test_data/sentences.txt
@@ -12,5 +12,6 @@ This sentence uses 10 identical variables: %%?x%% %%?x%% %%?x%% %%?x%% %%?x%% %%
This sentence uses either type a or b: %%a|b%%
This sentence uses a variable, then either type a or the same variable: %%?x%% %%a|?x%%
This sentence uses four completely random types: %%?%% %%?%% %%?%% %%?%%
-This sentence chooses the word 'foo' or 'bar': %%"foo"|"bar"%%
-This sentence chooses the word 'foo' or a word from type c: %%"foo"|c%%
+This sentence chooses the word 'foo' or 'bar': %%"foo|"bar%%
+This sentence chooses the word 'foo' or a word from type c: %%"foo|c%%
+Intentionally malformed: %%"fo|"o%%