Skip to content

Commit

Permalink
Addressed #198, correct decoding should only look at last separator.
Browse files Browse the repository at this point in the history
  • Loading branch information
asergeyev committed Apr 4, 2015
1 parent 015384b commit 3373659
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions idn/punycode.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ func decode(b []byte) []byte {
}
out := make([]rune, 0, len(b))
b = b[len(_PREFIX):]
for pos, x := range b {
if x == _DELIMITER {
for pos := len(b) - 1; pos >= 0; pos-- {
// only last delimiter is our interest
if b[pos] == _DELIMITER {
out = append(out, bytes.Runes(b[:pos])...)
b = b[pos+1:] // trim source string
break
Expand Down
3 changes: 3 additions & 0 deletions idn/punycode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ var testcases = [][2]string{
{"", ""},
{"a", "a"},
{"A-B", "a-b"},
{"A-B-C", "a-b-c"},
{"AbC", "abc"},
{"я", "xn--41a"},
{"zя", "xn--z-0ub"},
{"ЯZ", "xn--z-zub"},
{"а-я", "xn----7sb8g"},
{"إختبار", "xn--kgbechtv"},
{"آزمایشی", "xn--hgbk6aj7f53bba"},
{"测试", "xn--0zwm56d"},
Expand All @@ -24,6 +26,7 @@ var testcases = [][2]string{
{"טעסט", "xn--deba0ad"},
{"テスト", "xn--zckzah"},
{"பரிட்சை", "xn--hlcj6aya9esc7a"},
{"mamão-com-açúcar", "xn--mamo-com-acar-yeb1e6q"},
}

func TestEncodeDecodePunycode(t *testing.T) {
Expand Down

0 comments on commit 3373659

Please sign in to comment.