Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Closes #1777: ByteArray.binarySearch: Compare unsigned bytes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pocmo committed Jan 23, 2019
1 parent a52f896 commit 6d622a4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Expand Up @@ -27,17 +27,14 @@ internal fun ByteArray.binarySearch(labels: List<ByteArray>, labelIndex: Int): S

val publicSuffixLength = start + end - start

// Compare the bytes. Note that the file stores UTF-8 encoded bytes, so we must compare the
// unsigned bytes.

var compareResult: Int
var currentLabelIndex = labelIndex
var currentLabelByteIndex = 0
var publicSuffixByteIndex = 0

var expectDot = false
while (true) {
val byte0: Byte = if (expectDot) {
val byte0 = if (expectDot) {
expectDot = false
'.'.toByte()
} else {
Expand All @@ -46,7 +43,10 @@ internal fun ByteArray.binarySearch(labels: List<ByteArray>, labelIndex: Int): S

val byte1 = this[start + publicSuffixByteIndex] and BITMASK

compareResult = byte0 - byte1
// Compare the bytes. Note that the file stores UTF-8 encoded bytes, so we must compare the
// unsigned bytes.
@Suppress("EXPERIMENTAL_API_USAGE")
compareResult = (byte0.toUByte() - byte1.toUByte()).toInt()
if (compareResult != 0) {
break
}
Expand Down
Expand Up @@ -285,7 +285,6 @@ class PublicSuffixListTest {
"食狮.com.cn",
publicSuffixList.getPublicSuffixPlusOne("食狮.com.cn").await())
// https://github.com/mozilla-mobile/android-components/issues/1777
/*
assertEquals(
"食狮.公司.cn",
publicSuffixList.getPublicSuffixPlusOne("食狮.公司.cn").await())
Expand All @@ -296,7 +295,6 @@ class PublicSuffixListTest {
"shishi.公司.cn",
publicSuffixList.getPublicSuffixPlusOne("shishi.公司.cn").await())
assertNull(publicSuffixList.getPublicSuffixPlusOne("公司.cn").await())
*/
assertEquals(
"食狮.中国",
publicSuffixList.getPublicSuffixPlusOne("食狮.中国").await())
Expand All @@ -313,7 +311,6 @@ class PublicSuffixListTest {
"xn--85x722f.com.cn",
publicSuffixList.getPublicSuffixPlusOne("xn--85x722f.com.cn").await())
// https://github.com/mozilla-mobile/android-components/issues/1777
/*
assertEquals(
"xn--85x722f.xn--55qx5d.cn",
publicSuffixList.getPublicSuffixPlusOne("xn--85x722f.xn--55qx5d.cn").await())
Expand All @@ -324,7 +321,6 @@ class PublicSuffixListTest {
"shishi.xn--55qx5d.cn",
publicSuffixList.getPublicSuffixPlusOne("shishi.xn--55qx5d.cn").await())
assertNull(publicSuffixList.getPublicSuffixPlusOne("xn--55qx5d.cn").await())
*/
assertEquals(
"xn--85x722f.xn--fiqs8s",
publicSuffixList.getPublicSuffixPlusOne("xn--85x722f.xn--fiqs8s").await())
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Expand Up @@ -25,6 +25,9 @@ permalink: /changelog/
}
```

* **lib-publicsuffixlist**
* Fixed an issue when comparing domain labels against the public suffix list ([#1777](https://github.com/mozilla-mobile/android-components/issues/1777))

# 0.39.0

* [Commits](https://github.com/mozilla-mobile/android-components/compare/v0.38.0...v0.39.0)
Expand Down

0 comments on commit 6d622a4

Please sign in to comment.