Skip to content

Commit

Permalink
Fix bug where an equals sign in a filter argument confuses the key logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kjellmorten committed Sep 21, 2017
1 parent 2158ca0 commit 83dfc0b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 13 additions & 0 deletions lib/compile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import append from './filters/append'
import upper from './filters/upper'
import wrap from './filters/wrap'
import max from './filters/max'
import map from './filters/map'

import compile from './compile'

Expand Down Expand Up @@ -228,3 +229,15 @@ test('should compile prefix modifier before filter functions', (t) => {

t.deepEqual(ret, expected)
})

test('should compile filter function with equal sign in argument', (t) => {
const template = 'http://example.com/{type|map(entry=entries)}'
const expected = [
'http://example.com/',
{param: 'type', filters: [{function: map, args: ['entry=entries']}]}
]

const ret = compile(template)

t.deepEqual(ret, expected)
})
14 changes: 7 additions & 7 deletions lib/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ const compileParam = (explode) => (segment) => {
}
: {param: segment}

// Specified key
const keyParts = obj.param.split('=')
if (keyParts.length > 1) {
obj.key = keyParts[0]
obj.param = keyParts[1]
}

// Filter functions
const filterParts = obj.param.split('|')
if (filterParts.length > 1) {
Expand All @@ -67,6 +60,13 @@ const compileParam = (explode) => (segment) => {
obj.filters = [{function: filters.max, args: [prefixParts[1]]}].concat(obj.filters || [])
}

// Specified key
const keyParts = obj.param.split('=')
if (keyParts.length > 1) {
obj.key = keyParts[0]
obj.param = keyParts[1]
}

// Explode
if (explode) {
obj.explode = true
Expand Down

0 comments on commit 83dfc0b

Please sign in to comment.