Opened 11 years ago

Closed 11 years ago

#6039 closed defect (fixed)

DomParser: need support for element attributes defined using single quotes

Reported by: guest Owned by: Tom Trenka
Priority: high Milestone: 1.2
Component: Dojox Version: 1.0
Keywords: dojox xml DomParser Atom Cc: tdedischew@…
Blocked By: Blocking:

Description (last modified by Tom Trenka)

I'm using 1.0.2's dojox.xml.DomParser? to process Atom feeds and came across one that used single quotes today, and:

DomParser.js:33  var reAttr=/([^=]*)="([^"]*)"/g;

failed to match any attributes. The solution I use is:

// fix part 1: attr[3] and [4] will be matched double or single contents resp.
DomParser.js:33	var reAttr=/([^=]*)=("([^"]*)"|'([^']*)')/g;

...

DomParser.js: around line 300
...
//	parse the attribute string.
var attr;
while((attr=reAttr.exec(res[2]))!=null){
      if(attr.length>0){
        // fix part 2: roll up single attr[4] or double attr[3]
--->       attr[2]= attr[3] || attr[4];

           var name=attr[1].replace(trim,"");
           var val=attr[2].replace(normalize," ")
...

Attachments (1)

test_DomParserAttributeParsing.html (3.2 KB) - added by guest 11 years ago.
if it helps, here's a test case -tim

Download all attachments as: .zip

Change History (9)

comment:1 Changed 11 years ago by Tom Trenka

Milestone: 1.2
Owner: changed from Adam Peller to Tom Trenka

comment:2 Changed 11 years ago by Tom Trenka

You're correct: XML should support either single or double-quoted attributes. My bad.

When the dust settles around the 1.1 release, I'll replace that line with this:

var reAttr=/([=]*)=(['"])(['"]*)2/g

It's not your expression (yours is a little more inefficient but will work) but it will work.

Changed 11 years ago by guest

if it helps, here's a test case -tim

comment:3 Changed 11 years ago by guest

I actually tried using the back reference approach, but it won't work on mixed attribute content like:

<replace what='"' with="'" />

;) -Tim

comment:4 Changed 11 years ago by Tom Trenka

Description: modified (diff)
Summary: dojox.xml.DomParser -- support for element attributes defined using single quotesDomParser: need support for element attributes defined using single quotes

comment:5 Changed 11 years ago by Tom Trenka

Resolution: fixed
Status: newclosed

(In [14308]) Fixes #6039 by applying double or single quote RE to attribute parsing. !strict.

comment:6 Changed 11 years ago by Tom Trenka

(In [14430]) Bug in the attribute regular expression parsing fixed with additional grouping. Fixes #6039. !strict.

comment:7 Changed 11 years ago by Robert Coup

Resolution: fixed
Status: closedreopened

[14430] introduces an issue with parsing empty attributes...

console.log(dojox.xml.DomParser.parse('<z><p a="" >foo</p></z>'));

The code (line 312) is doing (""||undefined).replace(...) and its failing as "" evaluates to false so the expression result is undefined.

comment:8 Changed 11 years ago by Robert Coup

Resolution: fixed
Status: reopenedclosed

(In [14744]) Bug in the parsing of empty attributes introduced in [14430]. Fixes #6039. !strict

Note: See TracTickets for help on using tickets.