Skip to content

Commit 8a82eee

Browse files
committed
Fix unquoting strings
1 parent 6c754dc commit 8a82eee

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Diff for: lexer.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package expr
22

33
import (
44
"fmt"
5-
"strconv"
65
"strings"
76
"unicode"
87
"unicode/utf8"
@@ -250,11 +249,11 @@ Loop:
250249
break Loop
251250
}
252251
}
253-
word := strings.Trim(l.word(), `"'`)
254-
value, err := strconv.Unquote(`"` + word + `"`)
255-
if err != nil {
256-
return l.errorf("unquote error: %v", err)
257-
}
252+
q := string(quote)
253+
value := strings.Trim(l.word(), q)
254+
value = strings.Replace(value, "\\"+q, q, -1)
255+
value = strings.Replace(value, "\\n", "\n", -1)
256+
value = strings.Replace(value, "\\t", "\t", -1)
258257
l.emitValue(text, value)
259258
return lexRoot
260259
}

Diff for: lexer_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ var lexTests = []lexTest{
9797
{kind: eof},
9898
},
9999
},
100+
{
101+
`'\.'`,
102+
[]token{
103+
{kind: text, value: "\\."},
104+
{kind: eof},
105+
},
106+
},
100107
}
101108

102109
var lexErrorTests = []lexErrorTest{

0 commit comments

Comments
 (0)