diff --git a/V2rayNG/app/src/test/java/com/v2ray/ang/HttpUtilTest.kt b/V2rayNG/app/src/test/java/com/v2ray/ang/HttpUtilTest.kt new file mode 100644 index 00000000..207215e5 --- /dev/null +++ b/V2rayNG/app/src/test/java/com/v2ray/ang/HttpUtilTest.kt @@ -0,0 +1,41 @@ +package com.v2ray.ang + +import com.v2ray.ang.util.HttpUtil +import org.junit.Assert.assertEquals +import org.junit.Test + +class HttpUtilTest { + + @Test + fun testIdnToASCII() { + // Regular URL remains unchanged + val regularUrl = "https://example.com/path" + assertEquals(regularUrl, HttpUtil.idnToASCII(regularUrl)) + + // Non-ASCII URL converts to ASCII (Punycode) + val nonAsciiUrl = "https://例子.测试/path" + val expectedNonAscii = "https://xn--fsqu00a.xn--0zwm56d/path" + assertEquals(expectedNonAscii, HttpUtil.idnToASCII(nonAsciiUrl)) + + // Mixed URL only converts the host part + val mixedUrl = "https://例子.com/测试" + val expectedMixed = "https://xn--fsqu00a.com/测试" + assertEquals(expectedMixed, HttpUtil.idnToASCII(mixedUrl)) + + // URL with Basic Authentication using regular domain + val basicAuthUrl = "https://user:password@example.com/path" + assertEquals(basicAuthUrl, HttpUtil.idnToASCII(basicAuthUrl)) + + // URL with Basic Authentication using non-ASCII domain + val basicAuthNonAscii = "https://user:password@例子.测试/path" + val expectedBasicAuthNonAscii = "https://user:password@xn--fsqu00a.xn--0zwm56d/path" + assertEquals(expectedBasicAuthNonAscii, HttpUtil.idnToASCII(basicAuthNonAscii)) + + // URL with non-ASCII username and password + val nonAsciiAuth = "https://用户:密码@example.com/path" + // Basic auth credentials should remain unchanged as they're percent-encoded separately + assertEquals(nonAsciiAuth, HttpUtil.idnToASCII(nonAsciiAuth)) + } + + +} \ No newline at end of file diff --git a/V2rayNG/app/src/test/java/com/v2ray/ang/AngUnitTest.kt b/V2rayNG/app/src/test/java/com/v2ray/ang/UtilsTest.kt similarity index 99% rename from V2rayNG/app/src/test/java/com/v2ray/ang/AngUnitTest.kt rename to V2rayNG/app/src/test/java/com/v2ray/ang/UtilsTest.kt index 08d023dc..77dd53ab 100644 --- a/V2rayNG/app/src/test/java/com/v2ray/ang/AngUnitTest.kt +++ b/V2rayNG/app/src/test/java/com/v2ray/ang/UtilsTest.kt @@ -11,7 +11,7 @@ import org.junit.Test * * See [testing documentation](http://d.android.com/tools/testing). */ -class AngUnitTest { +class UtilsTest { @Test fun test_parseInt() {