Using '>' symbol in attribute values leads to parser error

SyntaxEditor Web Languages Add-on for WPF Forum

Posted 10 years ago by AlexanderB - Software Developer, Edifecs
Version: 13.1.0581
Avatar

Hello,

 

By some reason when I have '>' symbol in attribute value I get parser error "Attribute end value delimiter expected".

 

For example, such XML leads to parser error:

<color asd="abc > 8">brown</color>

 

It is reproducible in "XML Editor (Web Lang. Add-on)" demo as well.

 

According to XML specification, greater then symbol should be allowed in XML attributes. What options do I have to disable this kind of error, as our customers have lots of XML files with '>' in attributes.

 

Thank you,

Alexander

[Modified 10 years ago]

Comments (8)

Answer - Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Thanks for reporting this, we've fixed it for the next maintenance release.  Unfortunately we just did a release a couple days ago so it might be several weeks out before the next one.

The XML language in the Web Languages Add-on is a DynamicLexer.  If you want to try and fix it for now, you'd need to find the two lexical states related to quoted string attribute values on it and set their lexical scope's IsAncestorEndScopeCheckEnabled = false.  Then also modify the last lexical pattern in each state to be [^\\\"]+ instead of [^\\\"\\>]+.  That is effectively the change we made.


Actipro Software Support

Posted 10 years ago by AlexanderB - Software Developer, Edifecs
Avatar

I probably doing something wrong, but it does not work for me.

Could you please take a quick look at my code to let me know what is wrong

DynamicLexer lexer = (DynamicLexer)Document.Language.GetLexer();
foreach (DynamicLexicalState lexicalState in lexer.LexicalStates)
{
	if (lexicalState.Id == XmlLexicalStateId.StartTagAttributeDoubleQuoteValue || lexicalState.Id == XmlLexicalStateId.StartTagAttributeSingleQuoteValue)
	{
		foreach (DynamicLexicalScope lexicalScope in lexicalState.LexicalScopes)
		{
			lexicalScope.IsAncestorEndScopeCheckEnabled = false;
		}
		foreach (DynamicLexicalPatternGroup lexicalPatternGroup in lexicalState.LexicalPatternGroups)
		{
			foreach (DynamicLexicalPattern pattern in lexicalPatternGroup.Patterns)
			{
				if (pattern.Pattern == "[^\\\"\\>]+")
				{
					pattern.Pattern = "[^\\\"]+";
				}
				else if (pattern.Pattern == "[^\\\'\\>]+")
				{
					pattern.Pattern = "[^\\']+";
				}
			}						
		}
	}
}

 

This code does not fix original issue - parser error "Attribute end value delimiter expected", but it fixes for me another case - when user enters ">" symbol while editing attribute value, it disables automatic insertion of element closing tag.

Thank you in advance.

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Alexander,

First I would put breakpoints in each of your property setter lines to make sure they are being executed.  If you see that the Pattern property setter lines don't get hit, it could be that the escaping on the pattern string is incorrect when compared to how they are entered in XML.  If you step through the enumeration you should see where it should be getting caught and then update your string as needed.


Actipro Software Support

Posted 10 years ago by AlexanderB - Software Developer, Edifecs
Avatar

Hi,

I did it of course. Under debugger all seems fine, properties are set as expected, but it just does not fix original issue.

As far as I understand this code looks ok to you and nothing additional is required?

When next maintenance release with fixed functionality is expected? We are going to release our product next month, and this bug is a serious issue for us.

Thank you,

- Alexander.

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Alexander,

The next maintenance release will likely be in 2-3 weeks.  If you'd like a preview build to test, feel free to contact our support address and mention this thread.


Actipro Software Support

Posted 8 years ago by AlexanderB - Software Developer, Edifecs
Avatar

Looks like this issue appeared again in 15.1.0624.

Not sure it is fixed in 16.1.0633, but we are on the late stage of release cycle and cannot upgrade to newer version at this point.

I need assistance in applying a workaround for this issue, as my code above in this thread still does not fix the issue. Could you please help me to find what is wrong with this code?

Answer - Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

It looks like the lexer source was rebuilt since that original fix, when we added some more advanced features to the advanced XML syntax language.  This was noticed again in the 2016.1 timeframe and was resolved in v16.1.0632.

As for a workaround in 2015.1, that might be tricky.  The fix was that the pattern for the main LexicalPatternGroup in the StartTagAttributeDoubleQuoteValue lexical state was changed to "[^\\\"]+", and the pattern for the main LexicalPatternGroup in the StartTagAttributeSingleQuoteValue lexical state was changed to "[^\\\']+".  For the XML lexer in the add-on, we actually use the XML.langproj in the sample project and code generate the XmlLexer.cs class from that.  You could change the XML.langproj yourself per above using our Language Designer, then use it to code generate a new XmlLexer.cs.  After you create a normal instance of XmlSyntaxLanguage, do this call:

language.RegisterLexer(new MyXmlLexer(new XmlClassificationTypeProvider()));

That will get your updated lexer (assuming you renamed the class that was generated as MyXmlLexer) used for syntax highlighting.  The XmlParser also creates a lexer instance though.  You'd have to make a MyXmlParser class that inherits XmlParser and overrides this method:

public override ITokenReader CreateTokenReader(ITextBufferReader reader) {
	return new XmlTokenReader(reader, new MyXmlLexer(new XmlClassificationTypeProvider()));
}

Then back like above, you'd need to register this new parser in place of the old one:

language.RegisterParser(new MyXmlParser());

After you do those things, I believe it will work.  But again, the latest 2016.1 versions also have it working already.


Actipro Software Support

Posted 8 years ago by AlexanderB - Software Developer, Edifecs
Avatar

Thank you very much, it works great.

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.