concord icon indicating copy to clipboard operation
concord copied to clipboard

concord.escape function img regex shouldn't be greedy

Open andrewshell opened this issue 5 years ago • 0 comments

What I did:

I have an outline with html tags after an img tag. Ex: <img src="#" /><figcaption>Caption</figcaption>

What I expect to happen:

The &lt; and &gt; signs around figcaption should remain intact. Only the tags for img should be modified.

<img src="#" />&lt;figcaption&gt;Caption&lt;/figcaption&gt;

What happens:

The final &gt; sign around /figcaption is converted to > while the end &gt; of img remains intact.

<img src="#" /&gt;&lt;figcaption&gt;Caption&lt;/figcaption/>

The fix:

The regex on line 996 of concord.js https://github.com/scripting/concord/blob/master/concord.js#L996

Should change from: new RegExp("&lt;"+tag+"((?!&gt;).+)(/)?&gt;","gi")

to:

new RegExp("&lt;"+tag+"((?!&gt;).+?)(/)?&gt;","gi")

(see the ? after .+)

andrewshell avatar Nov 19 '20 23:11 andrewshell