From 17fa02b3d8a10ba7f9521aa7838c4c415a484df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Sun, 10 Apr 2022 16:04:12 +0900 Subject: [PATCH] <#> should be an invalid tag --- object.js | 4 ++++ string.js | 41 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/object.js b/object.js index 226821a..1765ca9 100644 --- a/object.js +++ b/object.js @@ -82,6 +82,10 @@ LStack.prototype.curr = function() { return this._first.o; }; +LStack.prototype.next = function() { + return this._first?.n?.o; +}; + LStack.prototype.empty = function() { return !this._first; } module.exports = { diff --git a/string.js b/string.js index c33e77e..054691b 100644 --- a/string.js +++ b/string.js @@ -51,11 +51,14 @@ module.exports = { for( let i = 0; i < l; i ++ ) { let c = str[i]; - let t, _a, _n; + let t = "", _a, _n; if( c === _OP ) { - t = str[ ++i ]; - let closeTag = ( t === "/" ); + let closeTag = ( str[ i + 1 ] === "/" ); + if( closeTag ) + { + t = str[ ++i ]; + } for( _a = str[ ++i ], _n = _a.charCodeAt(0); @@ -64,13 +67,32 @@ module.exports = { i ++, _a = str[i], _n = _a.charCodeAt(0) ) t += _a; + if( t === "" || t === "/" ) + { + // Hits "<#" where # is not a valid tag name + _fd( t + _a ); + continue; + } + if( _a === _ED ) { // Hits "" if( closeTag ) { + // Hits "..." with no corresponding open tag + if( tokenStack.empty() ) + { + if( _fineHandlers.UnmatchedCloseTag ) + { + _fineHandlers.UnmatchedCloseTag( ctx, t.substr( 1 ) ); + } + else + { + throw new Error( `Syntax Error: Unexpected closing ${_OP}${t}${_ED}` ); + } + } // Hits "..." - if( t.substr( 1 ) === tokenStack.curr().name ) + else if( t.substr( 1 ) === tokenStack.curr().name ) { let st = tokenStack.pop(); _fd = tokenStack.empty() ? _fd_strOut : tokenStack.curr().fd; @@ -80,7 +102,14 @@ module.exports = { // Hits "..." else { - throw new Error( `Syntax error: Unexpected closing ${_OP}${t}> after opened ${_OP}${tokenStack.curr().name}${_ED}` ); + if( _fineHandlers.UnmatchedCloseTag ) + { + _fineHandlers.UnmatchedCloseTag( ctx, t.substr( 1 ) ); + } + else + { + throw new Error( `Syntax error: Unexpected closing ${_OP}${t}${_ED} after opened ${_OP}${tokenStack.curr().name}${_ED}` ); + } } } // Hits "" @@ -121,6 +150,8 @@ module.exports = { // Write #... into abcd's attrs tokenStack.curr().attrs = t; _fd = tokenStack.curr().fd; + + _fineHandlers.TagOpen && _fineHandlers.TagOpen( ctx ); continue; } }