private string GetAttributeValue(IHtmlAttributeValueToken valueToken) { int start = valueToken.Start; if (valueToken.OpenQuote != '\0') { start++; } int end = valueToken.End; if (valueToken.Length > 1 && valueToken.CloseQuote != '\0') { end--; } if (end > start) { return(_cs.GetSubstringAt(start, end - start)); } return(String.Empty); }
public AttributeToken(IHtmlToken nameToken, int equalsPosition, IHtmlAttributeValueToken value) { NameToken = nameToken; EqualsSign = equalsPosition; ValueToken = value; }
internal AttributeToken GetAttributeState(int tagEnd, bool artifactTag, bool getValueInfo) { int eqPos = -1; bool isScript = false; IHtmlToken nameToken = null; AttributeToken attributeToken = null; _tokenizer.SkipWhitespace(); if (!_cs.IsEndOfStream()) { nameToken = _tokenizer.GetNameToken(tagEnd, artifactTag); // Allow whitespace before = per HTML standard _tokenizer.SkipWhitespace(); if (_cs.CurrentChar != '=' && nameToken != null) { // standalone attribute return(new AttributeToken(nameToken)); } if (_cs.CurrentChar == '=') { eqPos = _cs.Position; _cs.MoveToNextChar(); } IHtmlAttributeValueToken value = null; if (getValueInfo) { // Allow whitespace before = per HTML standard _tokenizer.SkipWhitespace(); // Check if attribute name begins with 'on' which means its value is script like // onclick="...". Script can legally include < > (like in if(x < y)... so we are // going to assume that everything between quotes is the script code. Note also // that script should always be quoted. If quote is missing, we assume that // attribute has no value. We cannot tell if attribute is script if attribute name // is an artifact, so we don't support <% %> = "script code". if (_cs.IsAtString() && nameToken != null && nameToken.Length >= 2) { char c1 = _cs[nameToken.Start]; char c2 = _cs[nameToken.Start + 1]; if ((c1 == 'o' || c1 == 'O') && (c2 == 'n' || c2 == 'N')) { isScript = true; } } value = GetAttributeValue(isScript, tagEnd); // In some odd cases we may end up with no name, no equals sign and no value. // Check if this is the case and if so, advance character stream position // and try again. if (nameToken != null || eqPos >= 0 || value != null) { attributeToken = new AttributeToken(nameToken, eqPos, value); } else { // We could not make sense at all - move on. _cs.MoveToNextChar(); } } } return(attributeToken); }
private string GetAttributeValue(IHtmlAttributeValueToken valueToken) { int start = valueToken.Start; if (valueToken.OpenQuote != '\0') start++; int end = valueToken.End; if (valueToken.Length > 1 && valueToken.CloseQuote != '\0') end--; if (end > start) return _cs.GetSubstringAt(start, end - start); return String.Empty; }