sanitized value in uri

This commit is contained in:
Ivan Socolsky 2014-12-19 16:01:58 -03:00 committed by Gustavo Maximiliano Cortez
parent 0be9ee9231
commit df48069c63
1 changed files with 14 additions and 3 deletions

View File

@ -420,8 +420,22 @@ angular.module('copayApp.controllers').controller('SendController',
};
$scope.setFromUri = function(uri) {
function sanitizeUri(uri) {
// Fixes when a region uses comma to separate decimals
var regex = /[\?\&]amount=(\d+([\,\.]\d+)?)/i;
var match = regex.exec(uri);
if (!match || match.length === 0) {
return uri;
}
var value = match[0].replace(',', '.');
var newUri = uri.replace(regex, value);
return newUri;
};
var form = $scope.sendForm;
uri = sanitizeUri(uri);
var parsed = new bitcore.BIP21(uri);
if (!parsed.isValid() || !parsed.address.isValid()) {
$scope.error = 'Invalid bitcoin URL';
@ -444,9 +458,6 @@ angular.module('copayApp.controllers').controller('SendController',
$scope.error = $scope.success = null;
if (!value) return '';
// Fixes when a region uses comma to separate decimals
value = value.replace(',', '.');
if (value.indexOf('bitcoin:') === 0) {
return $scope.setFromUri(value);
} else if (/^https?:\/\//.test(value)) {