diff options
author | Moonchild <moonchild@palemoon.org> | 2020-07-09 16:01:42 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2020-07-09 16:01:42 +0000 |
commit | 247ed6576c10b810589d25b23529b212b2c1efec (patch) | |
tree | 684c6900c1946373718475bbab6496ebc3904df9 /js | |
parent | 7bc3826bc9222e1200616585c27b2bacae3560eb (diff) | |
download | uxp-247ed6576c10b810589d25b23529b212b2c1efec.tar.gz |
[js] Improve readability and control flow of js date string parser.
Diffstat (limited to 'js')
-rwxr-xr-x | js/src/jsdate.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp index c6a369e2db..41722ffa91 100755 --- a/js/src/jsdate.cpp +++ b/js/src/jsdate.cpp @@ -21,6 +21,8 @@ #include "mozilla/FloatingPoint.h" #include "mozilla/Sprintf.h" +#include "nsCRT.h" + #include <ctype.h> #include <math.h> #include <string.h> @@ -958,11 +960,20 @@ ParseDate(const CharT* s, size_t length, ClippedTime* result) while (i < length) { int c = s[i]; i++; - if (c <= ' ' || c == ',' || c == '-') { - if (c == '-' && '0' <= s[i] && s[i] <= '9') + + // Spaces, ASCII control characters, and commas are ignored. + if (c <= ' ' || c == ',') + continue; + + // Dashes are delimiters if they're immediately followed by a number field. + // If they're not followed by a number field, they're simply ignored. + if (c == '-') { + if (i < length && nsCRT::IsAsciiDigit(s[i])) { prevc = c; + } continue; } + if (c == '(') { /* comments) */ int depth = 1; while (i < length) { @@ -977,7 +988,9 @@ ParseDate(const CharT* s, size_t length, ClippedTime* result) } continue; } - if ('0' <= c && c <= '9') { + + // Parse a number field. + if (nsCRT::IsAsciiDigit(c)) { int n = c - '0'; while (i < length && '0' <= (c = s[i]) && c <= '9') { n = n * 10 + c - '0'; |