Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
address review suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Bezzubov <bzz@apache.org>
  • Loading branch information
bzz committed Mar 28, 2019
1 parent 5430e59 commit fd6d585
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions driver/normalizer/strconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func contains(s string, c byte) bool {
// current implementation and found this was fastest.
func replaceEscapedMaybe(s, old, repl string) string {
var out strings.Builder
oldFirstRune, _ := utf8.DecodeRuneInString(old)
for s != "" {
pos := strings.Index(s, old)
if pos < 0 {
Expand All @@ -80,7 +81,7 @@ func replaceEscapedMaybe(s, old, repl string) string {
} else {
out.WriteString(repl)
}
if strings.IndexRune(old, r) == 0 { // old startsWith r
if oldFirstRune == r {
continue
}
s = s[n:]
Expand Down Expand Up @@ -171,10 +172,10 @@ func appendEscapedRune(buf []byte, r rune, quote byte) []byte {
return buf
}

// unquoteDouble is strconv.Unquote + JS-specific escape sequnce handling
// unquoteDouble is strconv.Unquote + JS-specific escape sequence handling.
func unquoteDouble(s string) (string, error) {
s = replaceEscapedMaybe(s, "\\0", "\x00") // treatment of special JS escape seq
ns, err := strconv.Unquote(s)
// Handle JS-specific escape sequences before removing quotes.
ns, err := strconv.Unquote(replaceEscapedMaybe(s, "\\0", "\x00"))
if err != nil {
return "", fmt.Errorf("%v (%s)", err, s)
}
Expand Down
2 changes: 1 addition & 1 deletion fixtures/string-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ var escClose = '\0CLOSE'+Math.random()+'\0';
var escComma = '\0COMMA'+Math.random()+'\0';
var escPeriod = '\0PERIOD'+Math.random()+'\0';

d = "\0\0\0\0\0\0\0\0"
d = "\0\0\0\0\0\0\0\0"

0 comments on commit fd6d585

Please sign in to comment.