Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -1024,11 +1024,16 @@ LibraryManager.library = {
return '%';
}
};

// Replace %% with a pair of NULLs (which cannot occur in a C string), then
// re-inject them after processing.
pattern = pattern.replace(/%%/g, '\0\0')
for (var rule in EXPANSION_RULES_2) {
if (pattern.includes(rule)) {
pattern = pattern.replace(new RegExp(rule, 'g'), EXPANSION_RULES_2[rule](date));
}
}
pattern = pattern.replace(/\0\0/g, '%')

var bytes = intArrayFromString(pattern, false);
if (bytes.length > maxsize) {
Expand Down
5 changes: 5 additions & 0 deletions tests/core/test_strftime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ int main() {
tm.tm_yday = 51;
tm.tm_isdst = 0;

// Test %% escaping
const char *fmt = "%%H=%H %%M=%m %%z=%z";
strftime(s, sizeof(s), fmt, &tm);
printf("%s -> %s\n", fmt, s);

size = strftime(s, 1000, "", &tm);
test((size == 0) && (*s == '\0'), "strftime test #1", s);

Expand Down
1 change: 1 addition & 0 deletions tests/core/test_strftime.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
%%H=%H %%M=%m %%z=%z -> %H=20 %M=02 %z=+0000
strftime test #1: 1
strftime test #2: 1
strftime test #3: 1
Expand Down