File tree 2 files changed +21
-17
lines changed
2 files changed +21
-17
lines changed Original file line number Diff line number Diff line change @@ -475,34 +475,35 @@ func bstrUnmarshal(s string) (result string) {
475
475
result += s [cursor :match [0 ]]
476
476
subStr := s [match [0 ]:match [1 ]]
477
477
if subStr == "_x005F_" {
478
+ cursor = match [1 ]
478
479
if l > match [1 ]+ 6 && ! escapeExp .MatchString (s [match [1 ]:match [1 ]+ 6 ]) {
479
480
result += subStr
480
- cursor = match [1 ]
481
- continue
482
- }
483
- if l > match [1 ]+ 5 && s [match [1 ]:match [1 ]+ 5 ] == "x005F" {
484
- result += "_"
485
- cursor = match [1 ]
486
- continue
487
- }
488
- if escapeExp .MatchString (subStr ) {
489
- result += "_"
490
- cursor = match [1 ]
491
481
continue
492
482
}
483
+ result += "_"
484
+ continue
493
485
}
494
486
if bstrExp .MatchString (subStr ) {
495
- x , _ := strconv .Unquote (`"\u` + s [match [0 ]+ 2 :match [1 ]- 1 ] + `"` )
487
+ cursor = match [1 ]
488
+ v , err := strconv .Unquote (`"\u` + s [match [0 ]+ 2 :match [1 ]- 1 ] + `"` )
489
+ if err != nil {
490
+ if l > match [1 ]+ 6 && escapeExp .MatchString (s [match [1 ]:match [1 ]+ 6 ]) {
491
+ result += subStr [:6 ]
492
+ cursor = match [1 ] + 6
493
+ continue
494
+ }
495
+ result += subStr
496
+ continue
497
+ }
496
498
hasRune := false
497
- for _ , c := range string ( x ) {
499
+ for _ , c := range v {
498
500
if unicode .IsControl (c ) {
499
501
hasRune = true
500
502
}
501
503
}
502
504
if ! hasRune {
503
- result += string ( x )
505
+ result += v
504
506
}
505
- cursor = match [1 ]
506
507
}
507
508
}
508
509
if cursor < l {
Original file line number Diff line number Diff line change @@ -237,19 +237,22 @@ func TestGenXMLNamespace(t *testing.T) {
237
237
238
238
func TestBstrUnmarshal (t * testing.T ) {
239
239
bstrs := map [string ]string {
240
- "*_x0000_" : "*" ,
241
240
"*" : "*" ,
241
+ "*_x0000_" : "*" ,
242
242
"*_x0008_" : "*" ,
243
243
"_x0008_*" : "*" ,
244
244
"*_x0008_*" : "**" ,
245
245
"*_x4F60__x597D_" : "*你好" ,
246
+ "*_xG000_" : "*_xG000_" ,
247
+ "*_xG05F_x0001_*" : "*_xG05F*" ,
246
248
"*_x005F__x0008_*" : "*_x005F_*" ,
247
249
"*_x005F_x0001_*" : "*_x0001_*" ,
250
+ "*_x005f_x005F__x0008_*" : "*_x005F_*" ,
251
+ "*_x005F_x005F_xG05F_x0006_*" : "*_x005F_xG05F*" ,
248
252
"*_x005F_x005F_x005F_x0006_*" : "*_x005F_x0006_*" ,
249
253
"_x005F__x0008_******" : "_x005F_******" ,
250
254
"******_x005F__x0008_" : "******_x005F_" ,
251
255
"******_x005F__x0008_******" : "******_x005F_******" ,
252
- "*_x005F_x005F__x0008_*" : "*_x005F_*" ,
253
256
}
254
257
for bstr , expected := range bstrs {
255
258
assert .Equal (t , expected , bstrUnmarshal (bstr ))
You can’t perform that action at this time.
0 commit comments