diff --git a/src/filters.js b/src/filters.js index 50aeb167c..874e444fc 100644 --- a/src/filters.js +++ b/src/filters.js @@ -94,7 +94,8 @@ const filters = { }) }, 'upcase': str => stringify(str).toUpperCase(), - 'url_encode': encodeURIComponent + 'url_decode': x => x.split('+').map(decodeURIComponent).join(' '), + 'url_encode': x => x.split(' ').map(encodeURIComponent).join('+') } function escape (str) { diff --git a/test/unit/filters.js b/test/unit/filters.js index 02843a208..612e2e2f0 100644 --- a/test/unit/filters.js +++ b/test/unit/filters.js @@ -395,11 +395,16 @@ describe('filters', function () { it('should support upcase', () => test('{{ "Parker Moore" | upcase }}', 'PARKER MOORE')) + describe('url_decode', function () { + it('should decode %xx and +', + () => test('{{ "%27Stop%21%27+said+Fred" | url_decode }}', "'Stop!' said Fred")) + }) + describe('url_encode', function () { it('should encode @', () => test('{{ "john@liquid.com" | url_encode }}', 'john%40liquid.com')) it('should encode ', - () => test('{{ "Tetsuro Takara" | url_encode }}', 'Tetsuro%20Takara')) + () => test('{{ "Tetsuro Takara" | url_encode }}', 'Tetsuro+Takara')) }) describe('obj_test', function () {