Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/issue345/filename.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bool MyFunction() {
func("double\\escaped\\string\\");
// comment
}
23 changes: 21 additions & 2 deletions processor/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,27 @@ func stringState(fileJob *FileJob, index int, endPoint int, stringTrie *Trie, en
return i, currentState
}

// If we are in a literal string we want to ignore the \ check OR we aren't checking for special ones
if ignoreEscape || fileJob.Content[i-1] != '\\' {
is_escaped := false
// if there is an escape symbol before us, investigate
if fileJob.Content[i-1] == '\\' {
num_escapes := 0
for j := i - 1; j > 0; j -= 1 {
if fileJob.Content[j] == '\\' {
num_escapes += 1
} else {
break
}
}

// if number of escapes is even, all escapes are themselves escaped
// otherwise the last escape does escape current string terminator
if num_escapes%2 != 0 {
is_escaped = true
}
}

// If we are in a literal string we want to ignore escapes OR we aren't checking for special ones
if ignoreEscape || !is_escaped {
if checkForMatchSingle(fileJob.Content[i], index, endPoint, endString, fileJob) {
return i, SCode
}
Expand Down
13 changes: 13 additions & 0 deletions test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,19 @@ do
fi
done

# Issue345 (https://github.com/boyter/scc/issues/345)
a=$(./scc "examples/issue345/" -f csv | sed -n '2 p')
b="C++,4,3,1,0,0,76"
if [ "$a" == "$b" ]; then
echo -e "{GREEN}PASSED string termination check"
else
echo -e "$a"
echo -e "${RED}======================================================="
echo -e "FAILED Should terminate the string properly"
echo -e "=======================================================${NC}"
exit
fi


# Extra case for longer languages that are normally truncated
for i in 'CloudFormation (YAM' 'CloudFormation (JSO'
Expand Down