From 96159557a2ac1867c746705c11ce0d405a6846be Mon Sep 17 00:00:00 2001 From: Nera Liu Date: Mon, 8 Jun 2015 15:13:00 +0800 Subject: [PATCH] add back the dist to master build. --- .gitignore | 1 - bower.json | 2 +- dist/secure-handlebars.js | 11951 ++++++++++++++++++++++++++++++++ dist/secure-handlebars.min.js | 19 + package.json | 2 +- 5 files changed, 11972 insertions(+), 3 deletions(-) create mode 100644 dist/secure-handlebars.js create mode 100644 dist/secure-handlebars.min.js diff --git a/.gitignore b/.gitignore index aed50fc..ec1ccd1 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,3 @@ coverage # build docs -dist diff --git a/bower.json b/bower.json index aacb3cc..ec696ba 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "secure-handlebars", - "version": "1.0.0", + "version": "1.0.1", "main": "dist/secure-handlebars.min.js", "authors": [ "Adonis Fung ", diff --git a/dist/secure-handlebars.js b/dist/secure-handlebars.js new file mode 100644 index 0000000..c7c7200 --- /dev/null +++ b/dist/secure-handlebars.js @@ -0,0 +1,11951 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Handlebars = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o + Albert Yu + Adonis Fung +*/ +/*jshint -W030 */ +(function() { +"use strict"; + +var stateMachine = require('./html5-state-machine.js'), + htmlState = stateMachine.State; + +/** + * @class FastParser + * @constructor FastParser + */ +function FastParser() { + + this.listeners = {}; + + this.state = stateMachine.State.STATE_DATA; /* Save the current status */ + this.tags = ['', '']; /* Save the current tag name */ + this.tagIdx = 0; + this.attrName = ''; /* Save the current attribute name */ + this.attributeValue = ''; /* Save the current attribute value */ + this.input = ''; + this.inputLen = 0; +} + +/** + * @function FastParser#on + * + * @param {string} eventType - the event type + * @param {function} listener - the event listener + * @returns this + * + * @description + *

register the given event listener to the given eventType

+ * + */ +FastParser.prototype.on = function (eventType, listener) { + var l = this.listeners[eventType]; + if (listener) { + if (l) { + l.push(listener); + } else { + this.listeners[eventType] = [listener]; + } + } + return this; +}; + +/** + * @function FastParser#once + * + * @param {string} eventType - the event type (e.g., preWalk, reWalk, postWalk, ...) + * @param {function} listener - the event listener + * @returns this + * + * @description + *

register the given event listener to the given eventType, for which it will be fired only once

+ * + */ +FastParser.prototype.once = function(eventType, listener) { + var self = this, onceListener; + if (listener) { + onceListener = function () { + self.off(eventType, onceListener); + listener.apply(self, arguments); + }; + return this.on(eventType, onceListener); + } + return this; +}; + +/** + * @function FastParser#off + * + * @param {string} eventType - the event type (e.g., preWalk, reWalk, postWalk, ...) + * @param {function} listener - the event listener + * @returns this + * + * @description + *

remove the listener from being fired when the eventType happen

+ * + */ +FastParser.prototype.off = function (eventType, listener) { + if (listener) { + var i, len, listeners = this.listeners[eventType]; + if (listeners) { + for (i = 0; listeners[i]; i++) { + if (listeners[i] === listener) { + listeners.splice(i, 1); + break; + } + } + } + } + return this; +}; + +/** + * @function FastParser#emit + * + * @param {string} eventType - the event type (e.g., preWalk, reWalk, postWalk, ...) + * @returns this + * + * @description + *

fire those listeners correspoding to the given eventType

+ * + */ +FastParser.prototype.emit = function (listeners, args) { + if (listeners) { + var i = -1, len; + if ((len = listeners.length)) { + while (++i < len) { + listeners[i].apply(this, args || []); + } + } + } + return this; +}; + +/* + * @function FastParser#walk + * + * @param {integer} i - the position of the current character in the input stream + * @param {string} input - the input stream + * @returns {integer} the new location of the current character. + * + */ +FastParser.prototype.walk = function(i, input, endsWithEOF) { + + var ch = input[i], + symbol = this.lookupChar(ch), + extraLogic = stateMachine.lookupAltLogicFromSymbol[symbol][this.state], + reconsume = stateMachine.lookupReconsumeFromSymbol[symbol][this.state]; + + /* Set state based on the current head pointer symbol */ + this.state = stateMachine.lookupStateFromSymbol[symbol][this.state]; + + /* See if there is any extra logic required for this state transition */ + switch (extraLogic) { + case 1: this.createStartTag(ch); break; + case 2: this.createEndTag(ch); break; + case 3: this.appendTagName(ch); break; + case 4: this.resetEndTag(ch); break; + case 6: /* match end tag token with start tag token's tag name */ + if(this.tags[0].toLowerCase() === this.tags[1].toLowerCase()) { + reconsume = 0; /* see 12.2.4.13 - switch state for the following case, otherwise, reconsume. */ + this.matchEndTagWithStartTag(symbol); + } + break; + case 8: this.matchEscapedScriptTag(ch); break; + case 11: this.processTagName(ch); break; + case 12: this.createAttributeNameAndValueTag(ch); break; + case 13: this.appendAttributeNameTag(ch); break; + case 14: this.appendAttributeValueTag(ch); break; + } + + if (reconsume) { /* reconsume the character */ + this.listeners.reWalk && this.emit(this.listeners.reWalk, [this.state, i, endsWithEOF]); + return this.walk(i, input); + } + + return i; +}; + +FastParser.prototype.createStartTag = function (ch) { + this.tagIdx = 0; + this.tags[0] = ch; +}; + +FastParser.prototype.createEndTag = function (ch) { + this.tagIdx = 1; + this.tags[1] = ch; +}; + +FastParser.prototype.appendTagName = function (ch) { + this.tags[this.tagIdx] += ch; +}; + +FastParser.prototype.resetEndTag = function (ch) { + this.tagIdx = 1; + this.tags[1] = ''; +}; + +FastParser.prototype.matchEndTagWithStartTag = function (symbol) { + /* Extra Logic #6 : + WHITESPACE: If the current end tag token is an appropriate end tag token, then switch to the before attribute name state. + Otherwise, treat it as per the 'anything else' entry below. + SOLIDUS (/): If the current end tag token is an appropriate end tag token, then switch to the this.closing start tag state. + Otherwise, treat it as per the 'anything else' entry below. + GREATER-THAN SIGN (>): If the current end tag token is an appropriate end tag token, then switch to the data state and emit the current tag token. + Otherwise, treat it as per the 'anything else' entry below. + */ + this.tags[0] = ''; + this.tags[1] = ''; + + switch (symbol) { + case stateMachine.Symbol.SPACE: /** Whitespaces */ + this.state = stateMachine.State.STATE_BEFORE_ATTRIBUTE_NAME; + return ; + case stateMachine.Symbol.SOLIDUS: /** [/] */ + this.state = stateMachine.State.STATE_SELF_CLOSING_START_TAG; + return ; + case stateMachine.Symbol.GREATER: /** [>] */ + this.state = stateMachine.State.STATE_DATA; + return ; + } +}; + +FastParser.prototype.matchEscapedScriptTag = function (ch) { + /* switch to the script data double escaped state if we see