{"action":"created","issue":{"url":"https://api.github.com/repos/i18next/i18next/issues/819","repository_url":"https://api.github.com/repos/i18next/i18next","labels_url":"https://api.github.com/repos/i18next/i18next/issues/819/labels{/name}","comments_url":"https://api.github.com/repos/i18next/i18next/issues/819/comments","events_url":"https://api.github.com/repos/i18next/i18next/issues/819/events","html_url":"https://github.com/i18next/i18next/issues/819","id":177857206,"number":819,"title":"Interpolator formatter exception leads to an error on next translation loop","user":{"login":"GillesRasigade","id":886331,"avatar_url":"https://avatars.githubusercontent.com/u/886331?v=3","gravatar_id":"","url":"https://api.github.com/users/GillesRasigade","html_url":"https://github.com/GillesRasigade","followers_url":"https://api.github.com/users/GillesRasigade/followers","following_url":"https://api.github.com/users/GillesRasigade/following{/other_user}","gists_url":"https://api.github.com/users/GillesRasigade/gists{/gist_id}","starred_url":"https://api.github.com/users/GillesRasigade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GillesRasigade/subscriptions","organizations_url":"https://api.github.com/users/GillesRasigade/orgs","repos_url":"https://api.github.com/users/GillesRasigade/repos","events_url":"https://api.github.com/users/GillesRasigade/events{/privacy}","received_events_url":"https://api.github.com/users/GillesRasigade/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-09-19T18:14:39Z","updated_at":"2016-09-20T13:57:49Z","closed_at":"2016-09-20T13:57:49Z","body":"If we define a custom formatter function which raises an exception, this one can be handled but let a wrong Interpolator state leading to an error on the next translation loop.\r\n\r\nI have the fix but can not push the branch due to permissions.\r\n\r\nCould you allow external contributors to push branches and create pull requests ?\r\n\r\nHere is the resulting patch.\r\n\r\nRegards,\r\n\r\n```patch\r\nFrom b4c9d5134627f8bbcb7d48e1234122e1262257d9 Mon Sep 17 00:00:00 2001\r\nFrom: Gilles Rasigade <gilles.rasigade@chauffeur-prive.com>\r\nDate: Mon, 19 Sep 2016 20:07:01 +0200\r\nSubject: [PATCH] Fix Interpolator formatter exception error propagation due to\r\n not reset RegExp indices\r\n\r\n---\r\n src/Interpolator.js        | 15 +++++++++++----\r\n test/interpolation.spec.js | 11 +++++++++++\r\n 2 files changed, 22 insertions(+), 4 deletions(-)\r\n\r\ndiff --git a/src/Interpolator.js b/src/Interpolator.js\r\nindex afd438d..89eb3df 100644\r\n--- a/src/Interpolator.js\r\n+++ b/src/Interpolator.js\r\n@@ -30,6 +30,15 @@ class Interpolator {\r\n     this.nestingSuffix = iOpts.nestingSuffix ? utils.regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || utils.regexEscape(')');\r\n \r\n     // the regexp\r\n+    this.resetRegExp();\r\n+  }\r\n+\r\n+  reset() {\r\n+    if (this.options) this.init(this.options);\r\n+  }\r\n+\r\n+  resetRegExp() {\r\n+    // the regexp\r\n     const regexpStr = this.prefix + '(.+?)' + this.suffix;\r\n     this.regexp = new RegExp(regexpStr, 'g');\r\n \r\n@@ -40,10 +49,6 @@ class Interpolator {\r\n     this.nestingRegexp = new RegExp(nestingRegexpStr, 'g');\r\n   }\r\n \r\n-  reset() {\r\n-    if (this.options) this.init(this.options);\r\n-  }\r\n-\r\n   interpolate(str, data, lng) {\r\n     let match, value;\r\n \r\n@@ -61,6 +66,8 @@ class Interpolator {\r\n       return this.format(utils.getPath(data, k), f, lng);\r\n     }\r\n \r\n+    this.resetRegExp();\r\n+\r\n     // unescape if has unescapePrefix/Suffix\r\n     while(match = this.regexpUnescape.exec(str)) {\r\n       let value = handleFormat(match[1].trim());\r\ndiff --git a/test/interpolation.spec.js b/test/interpolation.spec.js\r\nindex 8adada7..b19c694 100644\r\n--- a/test/interpolation.spec.js\r\n+++ b/test/interpolation.spec.js\r\n@@ -36,6 +36,7 @@ describe('Interpolator', () => {\r\n           format: function(value, format, lng) {\r\n             if (format === 'uppercase') return value.toUpperCase();\r\n             if (format === 'lowercase') return value.toLowerCase();\r\n+            if (format === 'throw') throw new Error('Formatter error');\r\n             return value;\r\n           }\r\n         }\r\n@@ -52,6 +53,16 @@ describe('Interpolator', () => {\r\n         expect(ip.interpolate.apply(ip, test.args)).to.eql(test.expected);\r\n       });\r\n     });\r\n+\r\n+    it('correctly manage exception in formatter', () => {\r\n+      expect(() => {\r\n+        ip.interpolate.apply(ip,  ['test {{test, throw}}', {test: 'up'}])\r\n+      }).to.throw(Error, 'Formatter error');\r\n+\r\n+      const test = tests[0];\r\n+\r\n+      expect(ip.interpolate.apply(ip, test.args)).to.eql(test.expected);\r\n+    });\r\n   });\r\n \r\n \r\n-- \r\n2.7.4\r\n\r\n\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/i18next/i18next/issues/comments/248308869","html_url":"https://github.com/i18next/i18next/issues/819#issuecomment-248308869","issue_url":"https://api.github.com/repos/i18next/i18next/issues/819","id":248308869,"user":{"login":"jamuhl","id":977772,"avatar_url":"https://avatars.githubusercontent.com/u/977772?v=3","gravatar_id":"","url":"https://api.github.com/users/jamuhl","html_url":"https://github.com/jamuhl","followers_url":"https://api.github.com/users/jamuhl/followers","following_url":"https://api.github.com/users/jamuhl/following{/other_user}","gists_url":"https://api.github.com/users/jamuhl/gists{/gist_id}","starred_url":"https://api.github.com/users/jamuhl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamuhl/subscriptions","organizations_url":"https://api.github.com/users/jamuhl/orgs","repos_url":"https://api.github.com/users/jamuhl/repos","events_url":"https://api.github.com/users/jamuhl/events{/privacy}","received_events_url":"https://api.github.com/users/jamuhl/received_events","type":"User","site_admin":false},"created_at":"2016-09-20T13:57:49Z","updated_at":"2016-09-20T13:57:49Z","body":"was merged..."}}
{"actor":{"display_login":"jamuhl"}}