dianping/cat · error · Error

invalid attribute:{qName}

Error message

invalid attribute:{qName}

What it means

ElementAttributes.add (worker-xml.js:1797-1803) validates every attribute name against the same tagNamePattern regex used for element names and throws on mismatch. An attribute name must be an XML Name: it cannot start with a digit, contain quotes, spaces, '=', '/', or '>'.

Source

Thrown at cat-home/src/main/webapp/assets/js/editor/worker-xml.js:1800

		}else{//error
			return -1;
		}
	}
	return -1;
}
function ElementAttributes(source){
	
}
ElementAttributes.prototype = {
	setTagName:function(tagName){
		if(!tagNamePattern.test(tagName)){
			throw new Error('invalid tagName:'+tagName)
		}
		this.tagName = tagName
	},
	add:function(qName,value,offset){
		if(!tagNamePattern.test(qName)){
			throw new Error('invalid attribute:'+qName)
		}
		this[this.length++] = {qName:qName,value:value,offset:offset}
	},
	length:0,
	getLocalName:function(i){return this[i].localName},
	getOffset:function(i){return this[i].offset},
	getQName:function(i){return this[i].qName},
	getURI:function(i){return this[i].uri},
	getValue:function(i){return this[i].value}
}




function _set_proto_(thiz,parent){
	thiz.__proto__ = parent;
	return thiz;
}

View on GitHub (pinned to e815e74d4c)

Solutions

  1. Check the attribute flagged in the message: give it a valid Name and a proper '=' and quoted value.
  2. If the name contains a quote character, the '=' before the preceding value is missing — restore it.
  3. Run the document through xmllint for a full list of malformed attributes.

Example fix

<!-- before -->
<link href"stylesheet.css">

<!-- after -->
<link href="stylesheet.css">
Defensive patterns

Strategy: type-guard

Validate before calling

// Validate attribute names before adding them:
function attrNameOk(name) {
  return /^[A-Za-z_:][-A-Za-z0-9_:.]*$/.test(name);
}
for (const k of Object.keys(attrs)) {
  if (!attrNameOk(k)) throw new TypeError('Invalid attribute name: ' + k);
}

Type guard

function isValidXmlAttribute(s) {
  return typeof s === 'string' && /^[A-Za-z_:][-A-Za-z0-9_:.]*$/.test(s) && !/[\s='\"/<>]/.test(s);
}

Try / catch

try {
  el.add(qName, value, offset);
} catch (ex) {
  if (/invalid attribute/.test(ex.message)) reportXmlError(ex); else throw ex;
}

Prevention

When it happens

Trigger: Attributes like '<a 1href="x">' (leading digit), '<a href"x">' (missing '=' makes the parser slice a name containing a quote), or names with stray punctuation. The add() test at line 1799-1801 throws.

Common situations: A missing '=' before a value causes the quote to be absorbed into the next name slice; copy-paste of HTML with weird attribute names; find/replace that deleted '=' characters; PHP/ASP-style short tags fed to a strict XML worker.

Related errors


AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14). Data as JSON: /api/errors/ca1b5b373828a486. Report an issue: GitHub.