added ua comment validator

This commit is contained in:
jash
2018-10-12 19:46:10 +02:00
committed by kexkey
parent 06204873b5
commit 3d6b0eb1fe
2 changed files with 10 additions and 0 deletions

View File

@@ -8,6 +8,8 @@ const path = require("path");
const featureChoices = require(path.join(__dirname, "features.json"));
const coinstring = require('coinstring');
const uaCommentRegexp = /^[a-zA-Z0-9 \.,:_\?@]+$/
let prompters = [];
const normalizedPath = path.join(__dirname, "prompters");
fs.readdirSync(normalizedPath).forEach(function(file) {
@@ -128,6 +130,13 @@ module.exports = class extends Generator {
return true;
}
_UACommentValidator( comment ) {
if( !uaCommentRegexp.test( comment ) ) {
throw new Error('Unsafe characters in UA comment. Please use only a-z, A-Z, 0-9, SPACE and .,:_?@');
}
return true;
}
_trimFilter( input ) {
return (input+"").trim();
}

View File

@@ -73,6 +73,7 @@ module.exports = {
name: 'bitcoin_uacomment',
default: utils._getDefault( 'bitcoin_uacomment' ),
message: prefix()+'Any UA comment?'+'\n',
validate: utils._UACommentValidator
}];
},
env: function( props ) {