You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Michael Osipov (Jira)" <ji...@apache.org> on 2020/12/26 23:02:00 UTC
[jira] [Commented] (MNG-6435) DefaultSettingsBuilder assumes all
SettingsReader/Writer impls will use XML
[ https://issues.apache.org/jira/browse/MNG-6435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17255132#comment-17255132 ]
Michael Osipov commented on MNG-6435:
-------------------------------------
I believe that [~ljnelson] is right. This piece of code is non-sense because a {{SettingsReader}} shall abstract from the serialization format. If the default XML reader cannot properly parse the base entities then it is broken and needs to be fixed. The parser is {{org.codehaus.plexus.util.xml.pull.MXParser}}. It seems to do the right thing:
{code:java}
protected char[] parseEntityRef()
throws XmlPullParserException, IOException
{
// entity reference http://www.w3.org/TR/2000/REC-xml-20001006#NT-Reference
// [67] Reference ::= EntityRef | CharRef
// ASSUMPTION just after &
entityRefName = null;
posStart = pos;
char ch = more();
if(ch == '#') {
// parse character reference
char charRef = 0;
ch = more();
if(ch == 'x') {
//encoded in hex
while(true) {
ch = more();
if(ch >= '0' && ch <= '9') {
charRef = (char)(charRef * 16 + (ch - '0'));
} else if(ch >= 'a' && ch <= 'f') {
charRef = (char)(charRef * 16 + (ch - ('a' - 10)));
} else if(ch >= 'A' && ch <= 'F') {
charRef = (char)(charRef * 16 + (ch - ('A' - 10)));
} else if(ch == ';') {
break;
} else {
throw new XmlPullParserException(
"character reference (with hex value) may not contain "
+printable(ch), this, null);
}
}
} else {
// encoded in decimal
while(true) {
if(ch >= '0' && ch <= '9') {
charRef = (char)(charRef * 10 + (ch - '0'));
} else if(ch == ';') {
break;
} else {
throw new XmlPullParserException(
"character reference (with decimal value) may not contain "
+printable(ch), this, null);
}
ch = more();
}
}
posEnd = pos - 1;
charRefOneCharBuf[0] = charRef;
if(tokenize) {
text = newString(charRefOneCharBuf, 0, 1);
}
return charRefOneCharBuf;
} else {
// [68] EntityRef ::= '&' Name ';'
// scan anem until ;
if(!isNameStartChar(ch)) {
throw new XmlPullParserException(
"entity reference names can not start with character '"
+printable(ch)+"'", this, null);
}
while(true) {
ch = more();
if(ch == ';') {
break;
}
if(!isNameChar(ch)) {
throw new XmlPullParserException(
"entity reference name can not contain character "
+printable(ch)+"'", this, null);
}
}
posEnd = pos - 1;
// determine what name maps to
final int len = posEnd - posStart;
if(len == 2 && buf[posStart] == 'l' && buf[posStart+1] == 't') {
if(tokenize) {
text = "<";
}
charRefOneCharBuf[0] = '<';
return charRefOneCharBuf;
//if(paramPC || isParserTokenizing) {
// if(pcEnd >= pc.length) ensurePC();
// pc[pcEnd++] = '<';
//}
} else if(len == 3 && buf[posStart] == 'a'
&& buf[posStart+1] == 'm' && buf[posStart+2] == 'p') {
if(tokenize) {
text = "&";
}
charRefOneCharBuf[0] = '&';
return charRefOneCharBuf;
} else if(len == 2 && buf[posStart] == 'g' && buf[posStart+1] == 't') {
if(tokenize) {
text = ">";
}
charRefOneCharBuf[0] = '>';
return charRefOneCharBuf;
} else if(len == 4 && buf[posStart] == 'a' && buf[posStart+1] == 'p'
&& buf[posStart+2] == 'o' && buf[posStart+3] == 's')
{
if(tokenize) {
text = "'";
}
charRefOneCharBuf[0] = '\'';
return charRefOneCharBuf;
} else if(len == 4 && buf[posStart] == 'q' && buf[posStart+1] == 'u'
&& buf[posStart+2] == 'o' && buf[posStart+3] == 't')
{
if(tokenize) {
text = "\"";
}
charRefOneCharBuf[0] = '"';
return charRefOneCharBuf;
} else {
final char[] result = lookuEntityReplacement(len);
if(result != null) {
return result;
}
}
if(tokenize) text = null;
return null;
}
}
{code}
> DefaultSettingsBuilder assumes all SettingsReader/Writer impls will use XML
> ---------------------------------------------------------------------------
>
> Key: MNG-6435
> URL: https://issues.apache.org/jira/browse/MNG-6435
> Project: Maven
> Issue Type: Improvement
> Components: Settings
> Affects Versions: 3.5.3
> Reporter: Laird Nelson
> Priority: Minor
> Fix For: 4.0.x-candidate
>
>
> On or around line 234, interpolation of settings assumes XML:
> {code}
> interpolator.addPostProcessor( new InterpolationPostProcessor()
> {
> @Override
> public Object execute( String expression, Object value )
> {
> if ( value != null )
> {
> // we're going to parse this back in as XML so we need to escape XML markup
> value = value.toString().replace( "&", "&" ).replace( "<", "<" ).replace( ">", ">" );
> return value;
> }
> return null;
> }
> } );
> {code}
> The value being interpolated here is the result of a {{SettingsWriter}}'s output. Obviously this kind of escaping doesn't make any sense if the {{SettingsWriter}} in question is not XML-based.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)