Skip to content

Commit

Permalink
Fix applying formatter with double-quoted arguments containing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
vkalinichev committed Dec 8, 2016
1 parent 7e05257 commit 5cb85a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions spec/rivets/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,21 @@ describe('Rivets.Binding', function() {
binding.formattedValue('jacket').should.equal('arg | with || pipes totally jacket')
})
})

describe('with a formatter string with quoted string arguments', function() {
beforeEach(function () {

view.formatters.reverse = function (value, first, second) {
return second + ' ' + first + ' ' + value
}

binding.formatters.push("reverse 'single quote' \"double quote\"")
})

it('applies the formatter with quoted string arguments', function () {
binding.formattedValue('jacket').should.equal('double quote single quote jacket')
})
})
})

describe('getValue()', function() {
Expand Down
2 changes: 1 addition & 1 deletion src/bindings.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Rivets.Binding
# formatted value.
formattedValue: (value) =>
for formatter, fi in @formatters
args = formatter.match /[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g
args = formatter.match /[^\s'"]+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g
id = args.shift()
formatter = @view.formatters[id]

Expand Down

0 comments on commit 5cb85a2

Please sign in to comment.