From 2aa5a3ba52edfc605d35e4a21e3bdea2ebc60326 Mon Sep 17 00:00:00 2001 From: wupengFEX Date: Fri, 13 Oct 2017 19:24:23 +0800 Subject: [PATCH 01/10] add mip-vd-baidu validate --- cases/212.html | 15 +++++++++++++++ cases/212.json | 1 + package.json | 2 +- rules.json | 13 +++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 cases/212.html create mode 100644 cases/212.json diff --git a/cases/212.html b/cases/212.html new file mode 100644 index 0000000..9751f7e --- /dev/null +++ b/cases/212.html @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/cases/212.json b/cases/212.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/cases/212.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/package.json b/package.json index 7c2e3aa..f0bf891 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mip-validator", - "version": "1.5.6", + "version": "1.5.7", "description": "MIP validator", "main": "index.js", "dependencies": { diff --git a/rules.json b/rules.json index 68ee2db..ed09a2c 100644 --- a/rules.json +++ b/rules.json @@ -336,5 +336,18 @@ "value": "/^\/$/" } } + }, + "mip-vd-baidu": { + "attrs": { + "src": { + "value": "/^(http(s)?:)?\/\//" + }, + "title": { + "value": "/^\\S+$/" + }, + "poster": { + "value": "/^(http(s)?:)?\/\//" + } + } } } From f12ca9db031b4b038db307528ae8d8d120aea371 Mon Sep 17 00:00:00 2001 From: wupengFEX Date: Mon, 16 Oct 2017 10:54:41 +0800 Subject: [PATCH 02/10] update regext --- rules.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rules.json b/rules.json index ed09a2c..a9a0d8f 100644 --- a/rules.json +++ b/rules.json @@ -80,7 +80,7 @@ "rel": "/^(?!(miphtml)|(canonical)|(standardhtml))$/" } }] - + } }, "script": [{ @@ -116,7 +116,7 @@ }, - + "img": { "disallow": true }, @@ -318,7 +318,7 @@ }, "duplicate": true, "mandatory_parent": "head" - + }, "template": { "attrs": { @@ -346,7 +346,7 @@ "value": "/^\\S+$/" }, "poster": { - "value": "/^(http(s)?:)?\/\//" + "value": "/^\\S+$/" } } } From f47c423bae3cc25f8ee428e107cf89b801409e1c Mon Sep 17 00:00:00 2001 From: wupengFEX Date: Thu, 19 Oct 2017 17:14:12 +0800 Subject: [PATCH 03/10] add rule --- package.json | 4 ++-- rules.json | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f0bf891..6833e41 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mip-validator", - "version": "1.5.7", + "version": "1.5.8", "description": "MIP validator", "main": "index.js", "dependencies": { @@ -76,4 +76,4 @@ ], "author": "harttle", "license": "ISC" -} \ No newline at end of file +} diff --git a/rules.json b/rules.json index a9a0d8f..8fa3f5f 100644 --- a/rules.json +++ b/rules.json @@ -340,12 +340,15 @@ "mip-vd-baidu": { "attrs": { "src": { + "mandatory": true, "value": "/^(http(s)?:)?\/\//" }, "title": { + "mandatory": true, "value": "/^\\S+$/" }, "poster": { + "mandatory": true, "value": "/^\\S+$/" } } From a47fc065fe1bd0f24453bd058b4c25e92959238f Mon Sep 17 00:00:00 2001 From: wupengFEX Date: Thu, 19 Oct 2017 18:39:24 +0800 Subject: [PATCH 04/10] add min js --- dist/mip-validator.js | 1405 +++++++++++++++++++------------------ dist/mip-validator.min.js | 4 +- package-lock.json | 2 +- package.json | 2 +- 4 files changed, 713 insertions(+), 700 deletions(-) diff --git a/dist/mip-validator.js b/dist/mip-validator.js index 2ca0bb0..79fcd53 100644 --- a/dist/mip-validator.js +++ b/dist/mip-validator.js @@ -16754,85 +16754,83 @@ function hasOwnProperty(obj, prop) { }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./support/isBuffer":56,"_process":36,"inherits":55}],58:[function(require,module,exports){ module.exports={ - "name": "mip-validator", - "version": "1.5.6", - "description": "MIP validator", - "main": "index.js", - "dependencies": { - "commander": "^2.9.0", - "jschardet": "^1.4.1", - "lodash": "^4.17.2", - "parse5": "^3.0.1" - }, - "browserify": { - "transform": [ - [ - "babelify", - { - "presets": [ - "es2015" - ], - "global": true - } - ], - [ - "aliasify", - { - "aliases": { - "jschardet": "./src/encoding/fake-jschardet.js", - "lodash": "./node_modules/lodash/lodash.min.js" - } - } - ] - ] - }, - "devDependencies": { - "aliasify": "^2.1.0", - "babel-preset-es2015": "^6.13.2", - "babelify": "^7.3.0", - "browserify": "^13.1.0", - "chai": "^3.5.0", - "chai-as-promised": "^6.0.0", - "changelog": "^1.0.7", - "coveralls": "^2.11.9", - "eslint": "^3.19.0", - "eslint-config-standard": "^10.2.1", - "eslint-plugin-import": "^2.2.0", - "eslint-plugin-mocha": "^4.9.0", - "eslint-plugin-node": "^4.2.2", - "eslint-plugin-promise": "^3.5.0", - "eslint-plugin-standard": "^3.0.1", - "git-changelog": "^1.0.1", - "istanbul": "^0.4.3", - "mocha": "^3.2.0", - "mock-fs": "^3.11.0", - "sinon": "^1.17.6", - "sinon-chai": "^2.8.0", - "supertest": "^2.0.1", - "uglifyjs": "^2.4.10" - }, - "scripts": { - "test": "DEBUG='mip-validator:' mocha", - "lint": "eslint src/ test/ bin/ index.js", - "preversion": "npm run lint && npm test", - "version": "make dist && git add -A dist", - "postversion": "git push && git push --tags && npm publish" - }, - "bin": { - "mip-validator": "./bin/cli.js", - "mip-validator-http": "./bin/http.js", - "mip-validator-socket": "./bin/socket.js" - }, - "repository": { - "type": "git", - "url": "ssh://git@github.com:mipengine/mip-validator.git" - }, - "keywords": [ - "MIP", - "validator" - ], - "author": "harttle", - "license": "ISC" + "name": "mip-validator", + "version": "1.5.8", + "description": "MIP validator", + "main": "index.js", + "dependencies": { + "commander": "^2.9.0", + "jschardet": "^1.4.1", + "lodash": "^4.17.2", + "parse5": "^3.0.1" + }, + "browserify": { + "transform": [ + [ + "babelify", { + "presets": [ + "es2015" + ], + "global": true + } + ], + [ + "aliasify", { + "aliases": { + "jschardet": "./src/encoding/fake-jschardet.js", + "lodash": "./node_modules/lodash/lodash.min.js" + } + } + ] + ] + }, + "devDependencies": { + "aliasify": "^2.1.0", + "babel-preset-es2015": "^6.13.2", + "babelify": "^7.3.0", + "browserify": "^13.1.0", + "chai": "^3.5.0", + "chai-as-promised": "^6.0.0", + "changelog": "^1.0.7", + "coveralls": "^2.11.9", + "eslint": "^3.19.0", + "eslint-config-standard": "^10.2.1", + "eslint-plugin-import": "^2.2.0", + "eslint-plugin-mocha": "^4.9.0", + "eslint-plugin-node": "^4.2.2", + "eslint-plugin-promise": "^3.5.0", + "eslint-plugin-standard": "^3.0.1", + "git-changelog": "^1.0.1", + "istanbul": "^0.4.3", + "mocha": "^3.2.0", + "mock-fs": "^3.11.0", + "sinon": "^1.17.6", + "sinon-chai": "^2.8.0", + "supertest": "^2.0.1", + "uglifyjs": "^2.4.10" + }, + "scripts": { + "test": "DEBUG='mip-validator:' mocha", + "lint": "eslint src/ test/ bin/ index.js", + "preversion": "npm run lint && npm test", + "version": "make dist && git add -A dist", + "postversion": "git push && git push --tags && npm publish" + }, + "bin": { + "mip-validator": "./bin/cli.js", + "mip-validator-http": "./bin/http.js", + "mip-validator-socket": "./bin/socket.js" + }, + "repository": { + "type": "git", + "url": "ssh://git@github.com:mipengine/mip-validator.git" + }, + "keywords": [ + "MIP", + "validator" + ], + "author": "harttle", + "license": "ISC" } },{}],59:[function(require,module,exports){ @@ -16937,7 +16935,7 @@ module.exports={ "rel": "/^(?!(miphtml)|(canonical)|(standardhtml))$/" } }] - + } }, "script": [{ @@ -16973,7 +16971,7 @@ module.exports={ }, - + "img": { "disallow": true }, @@ -17175,7 +17173,7 @@ module.exports={ }, "duplicate": true, "mandatory_parent": "head" - + }, "template": { "attrs": { @@ -17193,6 +17191,22 @@ module.exports={ "value": "/^\/$/" } } + }, + "mip-vd-baidu": { + "attrs": { + "src": { + "mandatory": true, + "value": "/^(http(s)?:)?\/\//" + }, + "title": { + "mandatory": true, + "value": "/^\\S+$/" + }, + "poster": { + "mandatory": true, + "value": "/^\\S+$/" + } + } } } @@ -17200,10 +17214,10 @@ module.exports={ 'use strict'; exports.detect = function () { - return { - encoding: 'UTF-8', - confidence: 1 - }; + return { + encoding: 'UTF-8', + confidence: 1 + }; }; },{}],62:[function(require,module,exports){ @@ -17215,11 +17229,11 @@ var allowedEncoding = ['UTF-8', 'ascii']; var logger = require('../logger.js')('mip-validator:encoding'); function checkUTF8(content, error) { - var result = jschardet.detect(content); - logger.debug('encoding detected:', result.encoding); - if (allowedEncoding.indexOf(result.encoding) === -1 && result.confidence >= 0.9) { - error(ERR.DISALLOWED_ENCODING, result.encoding); - } + var result = jschardet.detect(content); + logger.debug('encoding detected:', result.encoding); + if (allowedEncoding.indexOf(result.encoding) === -1 && result.confidence >= 0.9) { + error(ERR.DISALLOWED_ENCODING, result.encoding); + } } exports.checkUTF8 = checkUTF8; @@ -17240,14 +17254,14 @@ var checkUTF8 = require('./encoding').checkUTF8; var ValidateError = require('./error/validation-error.js'); function Engine(rules) { - assert(_.isObject(rules), 'rules must be object, ' + (typeof rules === 'undefined' ? 'undefined' : _typeof(rules)) + ' found'); + assert(_.isObject(rules), 'rules must be object, ' + (typeof rules === 'undefined' ? 'undefined' : _typeof(rules)) + ' found'); - var config = ruleParser.mkConfig(rules); - this.walker = Walker(config); + var config = ruleParser.mkConfig(rules); + this.walker = Walker(config); } Engine.prototype.register = function (validator) { - return this.walker.register(validator); + return this.walker.register(validator); }; /** @@ -17259,35 +17273,35 @@ Engine.prototype.register = function (validator) { * @param {string} options.type Optional, the sub type of MIP document, e.g. "custom" */ Engine.prototype.validate = function (html, options) { - var _this = this; + var _this = this; - html = normalize(html); - options = _.assign({ - fastMode: false, - rules: undefined, - type: undefined - }, options); + html = normalize(html); + options = _.assign({ + fastMode: false, + rules: undefined, + type: undefined + }, options); - logger.debug('validating using options %J', options); + logger.debug('validating using options %J', options); - return useErrorPolicy(function () { - var errorGenertor = ValidateError.generator({ - html: html, - fast: options.fastMode - }); + return useErrorPolicy(function () { + var errorGenertor = ValidateError.generator({ + html: html, + fast: options.fastMode + }); - checkUTF8(html, errorGenertor); - var document = parse(html, options); - behaveBuggyAsTheCPPVersion(document, errorGenertor); - _this.walker.validate(document, errorGenertor, html); - if (options.type) { - var rules = ruleParser.typedRules(options.type); - _this.walker.config = ruleParser.mkConfig(rules); - _this.walker.validate(document, errorGenertor, html); - } + checkUTF8(html, errorGenertor); + var document = parse(html, options); + behaveBuggyAsTheCPPVersion(document, errorGenertor); + _this.walker.validate(document, errorGenertor, html); + if (options.type) { + var rules = ruleParser.typedRules(options.type); + _this.walker.config = ruleParser.mkConfig(rules); + _this.walker.validate(document, errorGenertor, html); + } - return errorGenertor.errors; - }, options.fastMode); + return errorGenertor.errors; + }, options.fastMode); }; /* @@ -17295,110 +17309,109 @@ Engine.prototype.validate = function (html, options) { * @return {String} The normalized string */ function normalize(content) { - return content.toString().replace(/^\uFEFF/, ''); + return content.toString().replace(/^\uFEFF/, ''); } function useErrorPolicy(validate, fastMode) { - if (!fastMode) { - return validate(); - } - try { - validate(); - return []; - } catch (e) { - return [e]; - } + if (!fastMode) { + return validate(); + } + try { + validate(); + return []; + } catch (e) { + return [e]; + } } function parse(html, options) { - return parse5.parse(html, { - locationInfo: !options.fastMode - }); + return parse5.parse(html, { + locationInfo: !options.fastMode + }); } function behaveBuggyAsTheCPPVersion(doc, errorGenertor) { - var head = findFirstTagChild(findFirstTagChild(doc)); - var noscriptAppeared = false; - - head.childNodes.forEach(function (node) { - if (node.tagName === 'noscript') { - noscriptAppeared = true; - } else if (node.tagName && noscriptAppeared) { - // it's a tag after noscript - var err = ERR.INVALID_NOSCRIPT; - errorGenertor(err); - } - }); + var head = findFirstTagChild(findFirstTagChild(doc)); + var noscriptAppeared = false; + + head.childNodes.forEach(function (node) { + if (node.tagName === 'noscript') { + noscriptAppeared = true; + } else if (node.tagName && noscriptAppeared) { + // it's a tag after noscript + var err = ERR.INVALID_NOSCRIPT; + errorGenertor(err); + } + }); } function findFirstTagChild(parent) { - var ret; - parent.childNodes.some(function (node) { - ret = node; - return node.tagName; - }); - return ret; + var ret; + parent.childNodes.some(function (node) { + ret = node; + return node.tagName; + }); + return ret; } module.exports = Engine; },{"./../node_modules/lodash/lodash.min.js":11,"./encoding":62,"./error/dfn.json":64,"./error/validation-error.js":65,"./logger.js":66,"./rule-parser.js":68,"./walker.js":80,"assert":1,"parse5":17}],64:[function(require,module,exports){ module.exports={ - "DISALLOWED_ENCODING": { - "code": "06200001", - "message": "禁止使用'%s',请统一使用UTF-8编码" - }, - "INVALID_INNER_HTML": { - "code": "03210001", - "message": "标签 '%s' 的 HTML 内容不合法(%s)" - }, - "MANDATORY_TAG_MISSING": { - "code": "06200101", - "message": "强制性标签'%s'缺失或错误", - "misc": "去除该标签即可" - }, - "DISALLOWED_TAG": { - "code": "06200201", - "message": "禁止使用'%s'标签" - }, - "DUPLICATE_UNIQUE_TAG": { - "code": "06200701", - "message": "标签'%s'只能出现一次" - }, - "MANDATORY_ONEOF_ATTR_MISSING": { - "code": "06200501", - "message": "标签'%s'的强制性属性'%s'缺失" - }, - "DISALLOWED_ATTR": { - "code": "06200202", - "message": "'%s'标签中禁止使用'%s'属性" - }, - "INVALID_ATTR_VALUE": { - "code": "06200301", - "message": "标签'%s'中的属性'%s'的属性值'%s'无效" - }, - "DISALLOWED_TAG_ANCESTOR": { - "code": "06200801", - "message": "标签'%s'不应该是标签'%s'的子标签" - }, - "MANDATORY_TAG_ANCESTOR": { - "code": "06200901", - "message": "标签'%s'只能是标签'%s'的子级标签" - }, - "WRONG_PARENT_TAG": { - "code": "06200601", - "message": "标签'%s'的直接父标签应该是'%s',而不是'%s'" - }, - "INVALID_PROPERTY_VALUE_IN_ATTR_VALUE": { - "code": "06200401", - "message": "标签'%s'中的属性'%s'的属性'%s'被设置为'%s',该属性值无效" - }, - "INVALID_NOSCRIPT": { - "code": "06201001", - "message": "标签'