mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-07-31 20:11:23 +00:00
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:
@@ -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.
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user