From d915c77b7f2bdd7096e40a761b98bad8308ee529 Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Thu, 1 Aug 2013 00:33:33 -0700 Subject: [PATCH] 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. --- moment.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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); } -- 2.47.2