Pārlūkot izejas kodu

fix parser for escape

Darien Raymond 9 gadi atpakaļ
vecāks
revīzija
4e3ed19308
2 mainītis faili ar 4 papildinājumiem un 1 dzēšanām
  1. 2 1
      tools/conf/json/reader.go
  2. 2 0
      tools/conf/json/reader_test.go

+ 2 - 1
tools/conf/json/reader.go

@@ -4,6 +4,7 @@ import (
 	"io"
 )
 
+// State is the internal state of parser.
 type State byte
 
 const (
@@ -50,7 +51,7 @@ func (v *Reader) Read(b []byte) (int, error) {
 				p = append(p, x)
 			}
 		case StateEscape:
-			p = append(p, x)
+			p = append(p, '\\', x)
 			v.state = StateContent
 		case StateDoubleQuote:
 			switch x {

+ 2 - 0
tools/conf/json/reader_test.go

@@ -4,6 +4,7 @@ import (
 	"testing"
 
 	"bytes"
+
 	"v2ray.com/core/testing/assert"
 	. "v2ray.com/core/tools/conf/json"
 )
@@ -33,6 +34,7 @@ text text 2*`},
 		{`"//"content`, `"//"content`},
 		{`abcd'//'abcd`, `abcd'//'abcd`},
 		{`"\""`, `"\""`},
+		{`\"/*abcd*/\"`, `\"\"`},
 	}
 
 	for _, testCase := range data {