From: Iskren Chernev Date: Thu, 1 Aug 2013 07:33:33 +0000 (-0700) Subject: Fixed local formatting tokens detection X-Git-Tag: 2.2.0~34^2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=refs%2Fpull%2F971%2Fhead;p=thirdparty%2Fmoment.git Fixed local formatting tokens detection 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. --- diff --git a/moment.js b/moment.js index 2c1bf2c8e..bdf3c0d47 100644 --- a/moment.js +++ b/moment.js @@ -623,7 +623,8 @@ return m.lang().longDateFormat(input) || input; } - while (i-- && localFormattingTokens.test(format)) { + while (i-- && (localFormattingTokens.lastIndex = 0, + localFormattingTokens.test(format))) { format = format.replace(localFormattingTokens, replaceLongDateFormatTokens); }