Skip to content

Commit

Permalink
Merge 7ca9468 into 4a3f5e3
Browse files Browse the repository at this point in the history
  • Loading branch information
wupengFEX committed Jan 9, 2018
2 parents 4a3f5e3 + 7ca9468 commit 511b44f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
42 changes: 15 additions & 27 deletions rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}, {
"http-equiv": "/Content-Type/i"
}, {
"charset": "/^(UTF-8)/i"
"charset": "/^utf-8$/i"
}],
"attrs": {
"content": [{
Expand All @@ -35,15 +35,15 @@
},
"properties": {
"width": "device-width",
"initial-scale": "1"
"initial-scale": "/^1(\\.0)?$/"
}
}]
},
"mandatory_or": [{
"http-equiv": "/Content-Type/i",
"content": "/charset=(utf)|(UTF)-8/"
"content": "/charset=utf-8/i"
}, {
"charset": "/^(utf)|(UTF-8)/"
"charset": "/^utf-8$/i"
}],
"mandatory": {
"name": "/^(viewport)?/",
Expand All @@ -53,31 +53,25 @@
},
"link": {
"mandatory": [{
"rel": "/^(miphtml)|(canonical)|(standardhtml)$/"
"rel": "/^(canonical)|(standardhtml)$/"
}, {
"rel": "/^stylesheet$/",
"href": "/^(https:)?\/\/(mipcache.bdstatic.com\/static\/mipmain)|(m.baidu.com\/static\/ala\/sf\/static\/)|((https:)?\/\/mipcache.bdstatic.com\/static\/v\\d\/)|((https:)?\/\/c.mipcdn.com\/static\/v\\d\/)|((https:)?\/\/c.mipcdn.com\/static\/mipmain)/"
"href": "/^(https:)?\/\/((mipcache\\.bdstatic\\.com\/static\/mipmain-v\\d\\.\\d\\.\\d\\.css)|(c\\.mipcdn\\.com\/static\/mipmain-v\\d\\.\\d\\.\\d\\.css)|(mipcache\\.bdstatic\\.com\/static\/v\\d\/mip\\.css)|(c\\.mipcdn\\.com\/static\/v\\d\/mip\\.css))$/"
}],

"mandatory_parent": "head",
"duplicate": [{
"rel": "/^(miphtml)|(standardhtml)$/"
}, {
"rel": "/^(miphtml)|(canonical)$/"
}, {
"rel": "/^stylesheet$/",
"href": "/^(https:)?\/\/(mipcache.bdstatic.com\/static\/mipmain)|(m.baidu.com\/static\/ala\/sf\/static\/)|(c.mipcdn.com\/static\/mipmain)/"
"rel": "/^(canonical)|(standardhtml)$/"
}],
"attrs": {
"href": [{
"value": "/^(http(s)?:)?\/\//",
"match": {
"rel": "/^(miphtml)|(canonical)|(standardhtml)$/"
"rel": "/^(canonical)|(standardhtml)$/"
}
}, {
"value": "/^(?!\/[^\/])/",
"match": {
"rel": "/^(?!(miphtml)|(canonical)|(standardhtml))$/"
"rel": "/^(?!(canonical)|(standardhtml))$/"
}
}]

Expand All @@ -86,13 +80,12 @@
"script": [
{
"mandatory": {
"type": "/^(text\/javascript)?/",
"src": "/^(https:)?\/\/(mipcache.bdstatic.com\/static\/mipmain)|(m.baidu.com\/static\/ala\/sf\/static\/)|((https:)?\/\/mipcache.bdstatic.com\/static\/v\\d\/)|((https:)?\/\/c.mipcdn.com\/static\/v\\d\/)|((https:)?\/\/c.mipcdn.com\/static\/mipmain)/"
"src": "/^(https:)?\/\/((mipcache\\.bdstatic\\.com\/static\/mipmain-v\\d\\.\\d\\.\\d\\.js)|(c\\.mipcdn\\.com\/static\/mipmain-v\\d\\.\\d\\.\\d\\.js)|(mipcache\\.bdstatic\\.com\/static\/v\\d\/mip\\.js)|(c\\.mipcdn\\.com\/static\/v\\d\/mip\\.js))$/"
}
},
{
"match": {
"src": "/^(https:)?\/\/(mipcache.bdstatic.com\/static\/mipmain)|(m.baidu.com\/static\/ala\/sf\/static\/)|((https:)?\/\/mipcache.bdstatic.com\/static\/v\\d\/)|((https:)?\/\/c.mipcdn.com\/static\/v\\d\/)|((https:)?\/\/c.mipcdn.com\/static\/mipmain)/"
"src":"/^(https:)?\/\/((mipcache\\.bdstatic\\.com)|(c\\.mipcdn\\.com))/"
},
"attrs": {
"type": {
Expand All @@ -102,7 +95,7 @@
}, {
"match_ancestor": "head",
"match": {
"src":"/^((https:)?\/\/mipcache.bdstatic.com)|((https:)?\/\/m.baidu.com\/static\/ala\/sf\/static\/)|((https:)?\/\/c.mipcdn.com)/"
"src":"/^(https:)?\/\/((mipcache\\.bdstatic\\.com)|(c\\.mipcdn\\.com))/"
},
"attrs": {
"async": {
Expand All @@ -113,7 +106,7 @@
"disallow": true,
"match": {
"type": "/^(?!application\/(ld\\+)?json)/",
"src":"/^(?!((https:)?\/\/mipcache.bdstatic.com)|((https:)?\/\/m.baidu.com\/static\/ala\/sf\/static\/)|((https:)?\/\/c.mipcdn.com))/"
"src":"/^(?!((https:)?\/\/mipcache\\.bdstatic\\.com)|((https:)?\/\/c\\.mipcdn\\.com))/"
}
}, {
"disallowed_ancestor": "template"
Expand All @@ -126,9 +119,6 @@
}
}
},



"img": {
"disallow": true
},
Expand Down Expand Up @@ -174,8 +164,6 @@
"option": {
"mandatory_ancestor": "mip-form"
},


"a": {
"attrs": {
"href": {
Expand Down Expand Up @@ -212,7 +200,7 @@
}
},
"source": {
"mandatory_ancestor": "mip-video",
"mandatory_ancestor": "/picture|mip-video|mip-audio/",
"attrs": {
"src": {
"mandatory": true,
Expand Down Expand Up @@ -282,7 +270,7 @@
"mip-form": {
"attrs": {
"method": {
"value": "/^(post)|(get)$/i"
"value": "/^((post)|(get))$/i"
},
"url": {
"mandatory": true,
Expand Down
5 changes: 3 additions & 2 deletions src/validators/invalid_property_value_in_attr_value.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const _ = require('lodash')
const ERR = require('../error/dfn.json')
const matcher = require('../matcher.js')

exports.onAttr = function(attr, attrRule, node, nodeRule, error) {
if (!attrRule.properties) return
Expand All @@ -10,8 +11,8 @@ exports.onAttr = function(attr, attrRule, node, nodeRule, error) {
name: key,
value: obj[key]
}

if (property.value === value) return
if (matcher.matchValue(property.value, value)) return

error(ERR.INVALID_PROPERTY_VALUE_IN_ATTR_VALUE,
node.nodeName, attr.name,
Expand Down
3 changes: 2 additions & 1 deletion src/validators/mandatory_tag_ancestor.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const ERR = require('../error/dfn.json')
const matcher = require('../matcher.js')

exports.onNode = function(node, rule, error) {
if (!rule.mandatory_ancestor) return

for (var cur = node.parentNode; cur && cur.nodeName; cur = cur.parentNode) {
if (rule.mandatory_ancestor === cur.nodeName) {
if (matcher.matchValue(cur.nodeName, rule.mandatory_ancestor)) {
return
}
}
Expand Down

0 comments on commit 511b44f

Please sign in to comment.