Fix question marks could not be used in payment protocol request URI. Removes the check for multiple question marks in the bitcoin URI.

Also see https://github.com/schildbach/bitcoin-wallet/issues/169
This commit is contained in:
Andreas Schildbach
2014-11-07 11:15:58 +01:00
parent 6dbc918876
commit c2611b5345
2 changed files with 12 additions and 24 deletions

View File

@@ -151,7 +151,7 @@ public class BitcoinURI {
}
// Split off the address from the rest of the query parameters.
String[] addressSplitTokens = schemeSpecificPart.split("\\?");
String[] addressSplitTokens = schemeSpecificPart.split("\\?", 2);
if (addressSplitTokens.length == 0)
throw new BitcoinURIParseException("No data found after the bitcoin: prefix");
String addressToken = addressSplitTokens[0]; // may be empty!
@@ -161,12 +161,8 @@ public class BitcoinURI {
// Only an address is specified - use an empty '<name>=<value>' token array.
nameValuePairTokens = new String[] {};
} else {
if (addressSplitTokens.length == 2) {
// Split into '<name>=<value>' tokens.
nameValuePairTokens = addressSplitTokens[1].split("&");
} else {
throw new BitcoinURIParseException("Too many question marks in URI '" + uri + "'");
}
// Split into '<name>=<value>' tokens.
nameValuePairTokens = addressSplitTokens[1].split("&");
}
// Attempt to parse the rest of the URI parameters.

View File

@@ -305,23 +305,6 @@ public class BitcoinURITest {
assertEquals("aardvark=zebra", new BitcoinURI(MainNetParams.get(), BitcoinURI.BITCOIN_SCHEME + ":"
+ MAINNET_GOOD_ADDRESS + "?label=aardvark=zebra").getLabel());
}
/**
* Handles case when there are too many question marks
*
* @throws BitcoinURIParseException
* If something goes wrong
*/
@Test
public void testBad_TooManyQuestionMarks() throws BitcoinURIParseException {
try {
testObject = new BitcoinURI(MainNetParams.get(), BitcoinURI.BITCOIN_SCHEME + ":" + MAINNET_GOOD_ADDRESS
+ "?label=aardvark?message=zebra");
fail("Expecting BitcoinURIParseException");
} catch (BitcoinURIParseException e) {
assertTrue(e.getMessage().contains("Too many question marks"));
}
}
/**
* Handles unknown fields (required and not required)
@@ -409,4 +392,13 @@ public class BitcoinURITest {
assertEquals(ImmutableList.of(), uri.getPaymentRequestUrls());
assertNotNull(uri.getAddress());
}
@Test
public void testUnescapedPaymentProtocolReq() throws Exception {
BitcoinURI uri = new BitcoinURI(TestNet3Params.get(),
"bitcoin:?r=https://merchant.com/pay.php?h%3D2a8628fc2fbe");
assertEquals("https://merchant.com/pay.php?h=2a8628fc2fbe", uri.getPaymentRequestUrl());
assertEquals(ImmutableList.of("https://merchant.com/pay.php?h=2a8628fc2fbe"), uri.getPaymentRequestUrls());
assertNull(uri.getAddress());
}
}