]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fixed local formatting tokens detection 971/head
authorIskren Chernev <iskren.chernev@gmail.com>
Thu, 1 Aug 2013 07:33:33 +0000 (00:33 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Thu, 1 Aug 2013 07:33:33 +0000 (00:33 -0700)
According to the docs:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test
issuing regex.test on the same regex that is also g (global), would cause it to
remember the last match position and continue from there. Set lastIndex to
0 before every test to make sure this won't happen.

moment.js

index 2c1bf2c8e6607d2130029b93465a9019f14e8aad..bdf3c0d4728095283115bb94a9ddbf65d9c86957 100644 (file)
--- a/moment.js
+++ b/moment.js
             return m.lang().longDateFormat(input) || input;
         }
 
-        while (i-- && localFormattingTokens.test(format)) {
+        while (i-- && (localFormattingTokens.lastIndex = 0,
+                    localFormattingTokens.test(format))) {
             format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
         }