fix escape sequences when extracting string literals (#244)
Nick Snyder authored 3 years ago
GitHub committed 3 years ago
8 | 8 |
"io/ioutil"
|
9 | 9 |
"os"
|
10 | 10 |
"path/filepath"
|
|
11 |
"strconv"
|
11 | 12 |
"strings"
|
12 | 13 |
|
13 | 14 |
"github.com/nicksnyder/go-i18n/v2/i18n"
|
|
239 | 240 |
if v.Kind != token.STRING {
|
240 | 241 |
return "", false
|
241 | 242 |
}
|
242 | |
s := v.Value[1 : len(v.Value)-1]
|
243 | |
if v.Value[0] == '"' {
|
244 | |
s = strings.Replace(s, `\"`, `"`, -1)
|
|
243 |
s, err := strconv.Unquote(v.Value)
|
|
244 |
if err != nil {
|
|
245 |
return "", false
|
245 | 246 |
}
|
246 | 247 |
return s, true
|
247 | 248 |
case *ast.BinaryExpr:
|
31 | 31 |
ID: "Plural ID",
|
32 | 32 |
}
|
33 | 33 |
`,
|
|
34 |
},
|
|
35 |
{
|
|
36 |
name: "escape newline",
|
|
37 |
fileName: "file.go",
|
|
38 |
file: `package main
|
|
39 |
|
|
40 |
import "github.com/nicksnyder/go-i18n/v2/i18n"
|
|
41 |
|
|
42 |
var hasnewline = &i18n.Message{
|
|
43 |
ID: "hasnewline",
|
|
44 |
Other: "\nfoo\nbar\\",
|
|
45 |
}
|
|
46 |
`,
|
|
47 |
activeFile: []byte(`hasnewline = "\nfoo\nbar\\"
|
|
48 |
`),
|
34 | 49 |
},
|
35 | 50 |
{
|
36 | 51 |
name: "escape",
|