Fix AsciiBytes unicode decoding

Fix the decoding logic in the AsciiBytes `hashCode` and `matches` to
correctly deal with multi-byte encodings.

Fixes gh-12504
This commit is contained in:
Phillip Webb
2018-03-29 13:51:41 -07:00
parent 98a2a91d16
commit 9a64d3bf3f
2 changed files with 34 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -184,6 +184,18 @@ public class AsciiBytesTests {
matchesSameAsString("\ud83d\udca9");
}
@Test
public void hashCodeFromInstanceMatchesHashCodeFromString() {
String name = "fonts/宋体/simsun.ttf";
assertThat(new AsciiBytes(name).hashCode()).isEqualTo(AsciiBytes.hashCode(name));
}
@Test
public void instanceCreatedFromCharSequenceMatchesSameCharSequence() {
String name = "fonts/宋体/simsun.ttf";
assertThat(new AsciiBytes(name).matches(name, NO_SUFFIX)).isTrue();
}
private void matchesSameAsString(String input) {
assertThat(new AsciiBytes(input).matches(input, NO_SUFFIX)).isTrue();
}