Created
November 4, 2011 15:38
-
-
Save think49/1339609 to your computer and use it in GitHub Desktop.
is-textcontent-of-script.js : script要素の内容が正しいかを検査する(HTML5準拠)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* is-textcontent-of-script.js | |
* | |
* @version 1.0.1 | |
* @author think49 | |
* @see <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#restrictions-for-contents-of-script-elements">4.3.1.2 Restrictions for contents of script elements - HTML5 Standard</a> | |
*/ | |
'use strict'; | |
function isTextcontentOfScript (textContent) { | |
var script, escape, data1, not_data1, data2, not_data2, data3, not_data3, script_start, script_end, lt, slash, s, c, r, i, p, t, tag_end; | |
lt = '\x3C'; | |
slash = '/'; | |
s = '[Ss]'; | |
c = '[Cc]'; | |
r = '[Rr]'; | |
i = '[Ii]'; | |
p = '[Pp]'; | |
t = '[Tt]'; | |
tag_end = '[\x09\x0A\x0C\x20\x2F\x3E]'; | |
script_start = lt + s + c + r + i + p + t + tag_end; | |
script_end = lt + slash + s + c + r + i + p + t + tag_end; | |
not_data1 = '\x3C--'; | |
data1 = '(?:(?!' + not_data1 + ')[\\s\\S])*'; | |
not_data2 = '(?:' + script_start + '|--\x3E)'; | |
data2 = '(?:(?!' + not_data2 + ')[\\s\\S])*'; | |
not_data3 = '(?:' + script_end + '|--\x3E)'; | |
data3 = '(?:(?!' + not_data3 + ')[\\s\\S])*'; | |
escape = '\x3C--' + data2 + '(?:' + script_start + data3 + script_end + data2 + ')*'; | |
script = data1 + '(?:' + escape + '(?:' + script_start + data3 + ')?--\x3E' + data1 + ')*(?:' + escape + ')?'; | |
return new RegExp('^' + script + '$').test(textContent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考リンク。