Codebase list golang-github-nicksnyder-go-i18n.v2 / c587b0d
fix escape sequences when extracting string literals (#244) Nick Snyder authored 3 years ago GitHub committed 3 years ago
2 changed file(s) with 19 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
88 "io/ioutil"
99 "os"
1010 "path/filepath"
11 "strconv"
1112 "strings"
1213
1314 "github.com/nicksnyder/go-i18n/v2/i18n"
239240 if v.Kind != token.STRING {
240241 return "", false
241242 }
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
245246 }
246247 return s, true
247248 case *ast.BinaryExpr:
3131 ID: "Plural ID",
3232 }
3333 `,
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 `),
3449 },
3550 {
3651 name: "escape",