Skip to content

Commit

Permalink
issue-813 -- Adds enforce-domains flag to no-url-protocols rule
Browse files Browse the repository at this point in the history
  • Loading branch information
danwaz committed Aug 25, 2016
1 parent 54c25a9 commit a120002
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/rules/no-url-protocols.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@

var helpers = require('../helpers');

var isUrlRegex = /^(https?:)?\/\//;
var isUrlRegex = /^(https?:)?\/\//,
noProtocolRegex = /^(https?:)\/\//;

var stripQuotes = function (str) {
return str.substring(1, str.length - 1);
};

module.exports = {
'name': 'no-url-protocols',
'defaults': {},
'defaults': {
'enforce-domains' : true
},
'detect': function (ast, parser) {
var result = [];

ast.traverseByType('uri', function (uri) {
uri.traverse(function (item) {
if (item.is('string')) {
var stripped = stripQuotes(item.content);
var stripped = stripQuotes(item.content),
regexSelector = parser.options['enforce-domains'] ?
isUrlRegex : noProtocolRegex;

if (stripped.match(isUrlRegex)) {
if (stripped.match(regexSelector)) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'severity': parser.severity,
Expand Down

0 comments on commit a120002

Please sign in to comment.