diff --git a/HISTORY.md b/HISTORY.md index 06d34a5..00af72d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +========== + + * Fix encoding `%` as last character + 1.0.1 / 2016-06-09 ================== diff --git a/index.js b/index.js index ae77cc9..fc4906c 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,7 @@ module.exports = encodeUrl * @private */ -var ENCODE_CHARS_REGEXP = /(?:[^\x21\x25\x26-\x3B\x3D\x3F-\x5B\x5D\x5F\x61-\x7A\x7E]|%(?:[^0-9A-Fa-f]|[0-9A-Fa-f][^0-9A-Fa-f]))+/g +var ENCODE_CHARS_REGEXP = /(?:[^\x21\x25\x26-\x3B\x3D\x3F-\x5B\x5D\x5F\x61-\x7A\x7E]|%(?:[^0-9A-Fa-f]|[0-9A-Fa-f][^0-9A-Fa-f]|$))+/g /** * RegExp to match unmatched surrogate pair. diff --git a/test/test.js b/test/test.js index 5b215ec..b959ca1 100644 --- a/test/test.js +++ b/test/test.js @@ -67,7 +67,7 @@ describe('encodeUrl(url)', function () { }) it('should encode the "%" if not a valid sequence', function () { - assert.equal(encodeUrl('http://localhost/%foo%bar%zap'), 'http://localhost/%25foo%bar%25zap') + assert.equal(encodeUrl('http://localhost/%foo%bar%zap%'), 'http://localhost/%25foo%bar%25zap%25') }) })