Skip to content

Commit

Permalink
修改脚本正则
Browse files Browse the repository at this point in the history
  • Loading branch information
wupengFEX committed Jan 10, 2018
1 parent e9c1ce0 commit a7a4d7f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"srcset": "/^\\S+$/"
}],
"attrs": {
"href": {
"src": {
"value": "/^\\S+$/"
},
"srcset": {
Expand Down
1 change: 0 additions & 1 deletion src/matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function stringToRegex(str) {
*/
function matchValue(src, target) {
var re
if (!target || !src) return false
if ((re = stringToRegex(target))) {
var result = re.test(src)
return re.negate ? (!result) : result
Expand Down
10 changes: 9 additions & 1 deletion src/validators/mandatory_attr_or_missing.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ exports.onBegin = function(error, html, rules) {

exports.onNode = function(node, rule, error) {
if (!rule.attrs_or) return
var attrOccurrence = _.keyBy(node.attrs, 'name')

var matched = false
_.map(rule.attrs_or, pattern => {
if (!matcher.matchAttrs(node, pattern)) return
var isExisted = true
_.forOwn(pattern, (rules, attrName) => {
if (!attrOccurrence[attrName]) {
isExisted = false
return
}
})
if (!isExisted || !matcher.matchAttrs(node, pattern)) return
matched = true
})
if (!matched) {
Expand Down

0 comments on commit a7a4d7f

Please sign in to comment.