<#> should be an invalid tag

This commit is contained in:
斟酌 鵬兄 2022-04-10 16:04:12 +09:00
parent cf6fd2e35e
commit 17fa02b3d8
2 changed files with 40 additions and 5 deletions

View File

@ -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 = {

View File

@ -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 )
{
let closeTag = ( str[ i + 1 ] === "/" );
if( closeTag )
{
t = str[ ++i ];
let closeTag = ( t === "/" );
}
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 "</abcd>"
if( closeTag )
{
// Hits "...</abcd>" 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 "<abcd...>...</abcd>"
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 "<abcd>...</efgh>"
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 "<abcd>"
@ -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;
}
}