boyter / scc

Sloc, Cloc and Code: scc is a very fast accurate code counter with complexity calculations and COCOMO estimates written in pure Go
MIT License
6.28k stars 250 forks source link

Fix incorrect string escaping #386

Closed KAAtheWiseGit closed 1 year ago

KAAtheWiseGit commented 1 year ago

Previously, only one char got checked for escapes when parsing strings. This meant that strings such as "\" never got terminated, leading to incorrect parsing.

This commit adds a check which calculates the number of escapes pre-string ending to determine wherever the last escape is itself escaped or not.

This was prompted by issue #345, I also added a test case for it.

One important note is that I am unsure how much that impacts performance. The for loop is only accessed if the string has an escape before it, so it should be a fairly rare path.

boyter commented 1 year ago

Neat. Thanks for taking the time out to resolve this.