Skip to content

[FIX] end tag with space after name should be valid #2899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions lib/ace/mode/xml/sax.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
}
switch(source.charAt(i+1)){
case '/':
var end = source.indexOf('>',i+3);
var regex = new RegExp("\\s*>");
var subSource = source.substr(i+2);
var end = subSource.search(regex);
end = end + i + 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that doesn't seem the same.
So in case when I forget to close the tag:

<Select>
</Select

end would be -1 because indexOf wouldn't find it

but in the new code end would be -1 + i + 2, so something else entirely.
Can we change this to something like: end = endIndex === -1 ? endIndex: endIndex + i + 2

I am pretty sure it breaks something otherwise, because, this is the current error:
Screenshot 2023-11-02 at 14 23 16

And this is the new one:
Screenshot 2023-11-02 at 14 24 18

var tagName = source.substring(i+2,end);
var config;
if (parseStack.length > 1) {
Expand All @@ -108,7 +111,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
break;
}
var localNSMap = config.localNSMap;

if(config.tagName != tagName){
errorHandler.fatalError("end tag name: " + tagName + " does not match the current start tagName: "+config.tagName );
}
Expand All @@ -132,9 +135,9 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
default:
try{
locator&&position(i);

var el = new ElementAttributes();

//elStartEnd
var end = parseElementStartPart(source,i,el,entityReplacer,errorHandler);
var len = el.length;
Expand All @@ -155,8 +158,8 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
}
}
appendElement(el,domBuilder,parseStack);


if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
}else{
Expand All @@ -180,7 +183,7 @@ function copyLocator(f,t){
t.lineNumber = f.lineNumber;
t.columnNumber = f.columnNumber;
return t;

}

/**
Expand Down Expand Up @@ -368,7 +371,7 @@ function appendElement(el,domBuilder,parseStack){
}
//can not set prefix,because prefix !== ''
a.localName = localName ;
//prefix == null for no ns prefix attribute
//prefix == null for no ns prefix attribute
if(nsPrefix !== false){//hack!!
if(localNSMap == null){
localNSMap = {}
Expand All @@ -378,7 +381,7 @@ function appendElement(el,domBuilder,parseStack){
}
currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
a.uri = 'http://www.w3.org/2000/xmlns/'
domBuilder.startPrefixMapping(nsPrefix, value)
domBuilder.startPrefixMapping(nsPrefix, value)
}
}
var i = el.length;
Expand All @@ -390,7 +393,7 @@ function appendElement(el,domBuilder,parseStack){
a.uri = 'http://www.w3.org/XML/1998/namespace';
}if(prefix !== 'xmlns'){
a.uri = currentNSMap[prefix]

//{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
}
}
Expand All @@ -412,7 +415,7 @@ function appendElement(el,domBuilder,parseStack){
domBuilder.endElement(ns,localName,tagName);
if(localNSMap){
for(prefix in localNSMap){
domBuilder.endPrefixMapping(prefix)
domBuilder.endPrefixMapping(prefix)
}
}
}else{
Expand All @@ -438,7 +441,7 @@ function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBui
domBuilder.characters(text,0,text.length);
return elEndStart;
//}

}
}
return elStartEnd+1;
Expand All @@ -448,10 +451,17 @@ function fixSelfClosed(source,elStartEnd,tagName,closeMap){
var pos = closeMap[tagName];
if(pos == null){
//console.log(tagName)
pos = closeMap[tagName] = source.lastIndexOf('</'+tagName+'>')
var regex = new RegExp("</"+tagName+"\\s*>", "gi");
var match = source.match(regex);
if (match && match.length >= 1) {
var lastIndex = source.lastIndexOf(match[match.length-1]);
pos = closeMap[tagName] = lastIndex;
} else {
pos = -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also keep the same chain assignment from above here, so pos = closeMap[tagName] = -1 just to keep the previous logic the same.

}
}
return pos<elStartEnd;
//}
//}
}
function _copy(source,target){
for(var n in source){target[n] = source[n]}
Expand Down