From 5c62badfa8e2c457c99cf411d7ca8145be0a412e Mon Sep 17 00:00:00 2001
From: Benoit Lavenier <benoit.lavenier@e-is.pro>
Date: Wed, 16 Aug 2023 18:59:49 +0200
Subject: [PATCH] fix(qrcode): Fix scanning a QR code with a checksum AND
amount (e.g. 'june://<pubkey>:<checksum>?amount=100')
---
www/js/controllers/wot-controllers.js | 2 +-
www/js/services/bma-services.js | 16 +++++++++-------
www/js/services/device-services.js | 2 +-
www/js/services/http-services.js | 13 +++++++++++++
4 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/www/js/controllers/wot-controllers.js b/www/js/controllers/wot-controllers.js
index 3de5ff15..ce2ee21f 100644
--- a/www/js/controllers/wot-controllers.js
+++ b/www/js/controllers/wot-controllers.js
@@ -541,7 +541,7 @@ function WotLookupController($scope, $state, $q, $timeout, $focus, $location, $i
return;
}
BMA.uri.parse(result)
- .then(function(obj){
+ .then(function(obj) {
if (obj.pubkey) {
$scope.search.text = obj.pubkey;
}
diff --git a/www/js/services/bma-services.js b/www/js/services/bma-services.js
index 5ec00767..565e53ad 100644
--- a/www/js/services/bma-services.js
+++ b/www/js/services/bma-services.js
@@ -1016,14 +1016,14 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium.
}
// Uid
- else if (uri.startsWith('@') && exports.regexp.USER_ID.test(uid.substr(1))) {
+ else if (uri.startsWith('@') && exports.regexp.USER_ID.test(uid.substring(1))) {
resolve({
- uid: uid.substr(1)
+ uid: uid.substring(1)
});
}
// G1 protocols
- else if(uri.startsWith('june:') || uri.startsWith('web+june:')) {
+ else if (uri.startsWith('june:') || uri.startsWith('web+june:')) {
var parser = csHttp.uri.parse(uri);
// Pubkey (explicit path)
@@ -1052,9 +1052,9 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium.
}
// UID
- else if (parser.hostname && parser.hostname.startsWith('@') && exports.regexp.USER_ID.test(parser.hostname.substr(1))) {
+ else if (parser.hostname && parser.hostname.startsWith('@') && exports.regexp.USER_ID.test(parser.hostname.substring(1))) {
resolve({
- uid: parser.hostname.substr(1),
+ uid: parser.hostname.substring(1),
pathSegments: parser.pathSegments,
params: parser.searchParams
});
@@ -1088,12 +1088,14 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium.
// Validate checksum
if (result.pubkey && exports.regexp.PUBKEY_WITH_CHECKSUM.test(result.pubkey)) {
console.debug("[BMA.parse] Validating pubkey checksum... ");
- var matches = exports.regexp.PUBKEY_WITH_CHECKSUM.exec(uri);
+ var matches = exports.regexp.PUBKEY_WITH_CHECKSUM.exec(result.pubkey);
pubkey = matches[1];
var checksum = matches[2];
var expectedChecksum = csCrypto.util.pkChecksum(pubkey);
if (checksum !== expectedChecksum) {
- console.warn("[BMA.parse] Detecting a pubkey {"+pubkey+"} with checksum {" + checksum + "}, but expecting checksum is {" + expectedChecksum + "}");
+ console.warn("[BMA.parse] Detecting a pubkey {{0}} with checksum {{1}}, but expecting checksum is {{2}}".format(
+ pubkey, checksum, expectedChecksum
+ ));
throw {message: 'ERROR.PUBKEY_INVALID_CHECKSUM'};
}
result.pubkey = pubkey;
diff --git a/www/js/services/device-services.js b/www/js/services/device-services.js
index 9be7c782..4681bb12 100644
--- a/www/js/services/device-services.js
+++ b/www/js/services/device-services.js
@@ -88,7 +88,7 @@ angular.module('cesium.device.services', ['cesium.utils.services', 'cesium.setti
}
function scan(n) {
- if (!exports.enable) {
+ if (!exports.barcode.enable) {
return $q.reject("Barcode scanner not enable. Please call 'ionicReady()' once before use (e.g in app.js).");
}
var deferred = $q.defer();
diff --git a/www/js/services/http-services.js b/www/js/services/http-services.js
index 1ccd538c..22463b5f 100644
--- a/www/js/services/http-services.js
+++ b/www/js/services/http-services.js
@@ -371,6 +371,19 @@ angular.module('cesium.http.services', ['cesium.cache.services'])
if (hostname.indexOf('?') !== -1) {
hostname = hostname.substr(0, path.indexOf('?'));
}
+
+ if (hostname.indexOf(':') !== -1) {
+ var port = hostname.substring(path.indexOf(':')+1);
+ var cleanHostName = hostname.substr(0, path.indexOf(':'));
+ // Invalid port (e.g. a checksum) => remove it (otherwise net <a> parser will failed to parse the URI)
+ if (isNaN(parseInt(port))) {
+ path = cleanHostName + path.substring(hostname.length);
+ }
+ else {
+ hostname = cleanHostName;
+ }
+ }
+ // Clean path
uri = 'http://' + path;
}
--
GitLab