BitcoinURI: Allow uppercase schema.

This commit is contained in:
Andreas Schildbach 2019-03-22 21:36:47 +01:00
parent db51bb257c
commit 0ea885fa10
2 changed files with 14 additions and 2 deletions

View file

@ -146,9 +146,10 @@ public class BitcoinURI {
String blockchainInfoScheme = scheme + "://";
String correctScheme = scheme + ":";
String schemeSpecificPart;
if (input.startsWith(blockchainInfoScheme)) {
final String inputLc = input.toLowerCase(Locale.US);
if (inputLc.startsWith(blockchainInfoScheme)) {
schemeSpecificPart = input.substring(blockchainInfoScheme.length());
} else if (input.startsWith(correctScheme)) {
} else if (inputLc.startsWith(correctScheme)) {
schemeSpecificPart = input.substring(correctScheme.length());
} else {
throw new BitcoinURIParseException("Unsupported URI scheme: " + uri.getScheme());

View file

@ -29,6 +29,8 @@ import org.bitcoinj.core.SegwitAddress;
import static org.junit.Assert.*;
import java.util.Locale;
public class BitcoinURITest {
private BitcoinURI testObject = null;
@ -101,6 +103,15 @@ public class BitcoinURITest {
assertEquals("Unexpected label", 20, testObject.getAddress().getHash().length);
}
@Test
public void testGood_uppercaseScheme() throws BitcoinURIParseException {
testObject = new BitcoinURI(MAINNET, BITCOIN_SCHEME.toUpperCase(Locale.US) + ":" + MAINNET_GOOD_ADDRESS);
assertEquals(MAINNET_GOOD_ADDRESS, testObject.getAddress().toString());
assertNull("Unexpected amount", testObject.getAmount());
assertNull("Unexpected label", testObject.getLabel());
assertEquals("Unexpected label", 20, testObject.getAddress().getHash().length);
}
@Test
public void testGood_segwit() throws BitcoinURIParseException {
testObject = new BitcoinURI(MAINNET, BITCOIN_SCHEME + ":" + MAINNET_GOOD_SEGWIT_ADDRESS);