mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-01 13:01:21 -03:00
gettext: enforce trimmed msgids
Now that we have trimmed our msgids, add an assertion to ensure that they stay trimmed. Note that we don't check msgstrs. We could do so when building the maps which get put into the executable, but there we also include messages originating from fish scripts, and there we don't enforce trimmed messages, so limiting the checks to only messages originating from the Rust code there would not be trivial. Closes #12405
This commit is contained in:
committed by
Johannes Altmanninger
parent
a33363902c
commit
a9ab708494
@@ -51,6 +51,14 @@ fn write_po_entry_to_file(message: &TokenStream, dir: &OsString) {
|
||||
!message_string.contains('\n'),
|
||||
"Gettext strings may not contain unescaped newlines. Unescaped newline found in '{message_string}'"
|
||||
);
|
||||
let msgid_without_quotes = &message_string[1..(message_string.len() - 1)];
|
||||
// We don't want leading or trailing whitespace in our messages.
|
||||
let trimmed_msgid = msgid_without_quotes.trim();
|
||||
assert_eq!(msgid_without_quotes, trimmed_msgid);
|
||||
assert!(!trimmed_msgid.starts_with("\\n"));
|
||||
assert!(!trimmed_msgid.ends_with("\\n"));
|
||||
assert!(!trimmed_msgid.starts_with("\\t"));
|
||||
assert!(!trimmed_msgid.ends_with("\\t"));
|
||||
// Crude check for format strings. This might result in false positives.
|
||||
let format_string_annotation = if message_string.contains('%') {
|
||||
"#, c-format\n"
|
||||
|
||||
Reference in New Issue
Block a user