Skip to content

Commit

Permalink
Fix text replacement for text with regex characters
Browse files Browse the repository at this point in the history
  • Loading branch information
nvh committed Feb 20, 2018
1 parent 8616043 commit 03ae78d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion framer/StyledText.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class InlineStyle
replaceText: (search, replace) ->
regex = null
if _.isString search
regex = new RegExp(search, 'g')
regex = new RegExp(Utils.escapeForRegex(search), 'g')
else if search instanceof RegExp
regex = search
if regex?
Expand Down
6 changes: 6 additions & 0 deletions test/tests/TextLayerTest.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,12 @@ describe "TextLayer", ->
subject.text.should.equal "Headier\nSubtitle\nLeadier Bodie text"
subject._styledText.validate().should.equal true

it "should escape regex characters in string", ->
subject.text = "This costs $123"
subject.textReplace("$123", "$456")
subject.text.should.equal "This costs $456"
subject._styledText.validate().should.equal true

it "should rerender the text when replacing it", ->
htmlBefore = subject.html
subject.textReplace("a", "b")
Expand Down

0 comments on commit 03ae78d

Please sign in to comment.