Permalink
Browse files

Fix text replacement for text with regex characters

  • Loading branch information...
nvh committed Feb 20, 2018
1 parent 8616043 commit 03ae78d72ed7ad8af4842fd64ae3b4c96815270b
Showing with 7 additions and 1 deletion.
  1. +1 −1 framer/StyledText.coffee
  2. +6 −0 test/tests/TextLayerTest.coffee
@@ -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?
@@ -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")

0 comments on commit 03ae78d

Please sign in to comment.