[Expat-bugs]
[ expat-Bugs-692964 ] Case where expat 1.95.6 doesn't report
duplicate attributes.
SourceForge.net
noreply at sourceforge.net
Mon Mar 3 11:36:42 EST 2003
Bugs item #692964, was opened at 2003-02-25 10:28
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=110127&aid=692964&group_id=10127
Category: None
Group: None
Status: Open
Resolution: Accepted
Priority: 5
Submitted By: Mark E. (snowballville)
>Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: Case where expat 1.95.6 doesn't report duplicate attributes.
Initial Comment:
I believe I found a bug in the Expat parser in
detecting duplicate attributes when using namespaces.
I'm using Expat 1.95.6 with PyXML 0.8.2.
Section 6.3 of the Namespaces 1.1 recommendation
requires that no element have two attributes with the
same expanded name. Expat 1.95.6 does indeed report a
duplicate attribute error with the example given in
that section of the document:
<?xml version="1.1"?>
<x xmlns:n1="http://www.w3.org"
xmlns:n2="http://www.w3.org" >
<bad a="1" a="2" />
<bad n1:a="1" n2:a="2" />
</x>
I've attached a file with the first <bad> element
removed. Expat doesn't report a duplicate attribute
error when processing this file as I believe the
recommendation requires.
----------------------------------------------------------------------
>Comment By: Karl Waclawek (kwaclaw)
Date: 2003-03-03 14:36
Message:
Logged In: YES
user_id=290026
The submitted fix - NSAttFix1.diff - seems to work, but
has a bad worst case behaviur. For example: assuming
20 attributes in an element, checking for duplicates
will require n*(n-1)/2 = 190 string comparisons.
I have therefore replaced this with a simplified hash
table approach. See the attached file NSAttFix3.diff.
In addition, this new patch also fixes bug #695401:
"Unbound prefixes not rejected".
Several cosmetic changes and some cleanup
(removed non-NULL checks when releasing memory)
are also included.
This requires some more testing. Currently it passes
the OASIS xml test suite the same as version 1.95.6.
Assigned to Fred for writing the regression tests.
----------------------------------------------------------------------
Comment By: Mark E. (snowballville)
Date: 2003-03-01 11:47
Message:
Logged In: YES
user_id=684927
I checked out the source and built it with DJGPP after
applying the patch. I used xmlwf to test the "bad" example I
provided and it is flagged as a duplicate error now. Whether
the solution is good or not I'll leave to those who know the
source.
----------------------------------------------------------------------
Comment By: Karl Waclawek (kwaclaw)
Date: 2003-02-28 14:01
Message:
Logged In: YES
user_id=290026
It turned out that Expat is very resilient against
patching this properly without having to re-write major
portions of the code that handles attributes and their
declarations.
I finally decided on a patch that simply hooks into the
loop in storeAtts() were prefixed attribute names are
expanded. The basic approach is to progressively store
the attributes' local names and uris in an array (nsAtts)
as they are iterated over, and each time a new attribute
name is expanded, it is compared to all previous local
names and uris (for the same element).
I tried to do this efficiently, but one can expect a slight
impact on performance.
Feel free to come up with a better solution.
Please test the attached patch (file NSAttFix.diff) for
both functional correctness and performance
(the patch includes a few cosmetic changes - not to
be confused).
----------------------------------------------------------------------
Comment By: Mark E. (snowballville)
Date: 2003-02-25 17:33
Message:
Logged In: YES
user_id=684927
I tried expat 1.95.5 with the same result.
----------------------------------------------------------------------
Comment By: Karl Waclawek (kwaclaw)
Date: 2003-02-25 14:02
Message:
Logged In: YES
user_id=290026
Well, if it is not too much effort, it certainly would
be useful information. Thanks,
Karl
----------------------------------------------------------------------
Comment By: Mark E. (snowballville)
Date: 2003-02-25 13:24
Message:
Logged In: YES
user_id=684927
Correction: I have used expat 1.95.5 (with pyxml 0.8.1), but
I haven't tested this case with it. I will if you want me
to. I would expect the same result though.
----------------------------------------------------------------------
Comment By: Karl Waclawek (kwaclaw)
Date: 2003-02-25 13:23
Message:
Logged In: YES
user_id=290026
It looks to me as if this error has always been there,
since the modifications required would be significant.
No need to test 1.95.5.
Karl
----------------------------------------------------------------------
Comment By: Mark E. (snowballville)
Date: 2003-02-25 13:21
Message:
Logged In: YES
user_id=684927
I just got started with using xml with python, so expat
1.95.6 (installed with pyxml 0.8.2) is the only version I've
used. I could temporarily download to pyxml 0.8.1 (which
includes expat 1.95.5) if you think it informative.
----------------------------------------------------------------------
Comment By: Karl Waclawek (kwaclaw)
Date: 2003-02-25 11:35
Message:
Logged In: YES
user_id=290026
Had a look. Won't be a quick fix.
The problem function is StoreAtts().
The solution might be to have a separate function
getAttributeIdNS() that looks up attribute id structs
by expanded instead of prefixed name.
But that may require adjustments to other parts of
the code. Hope I have time soon, unless someone else
is quicker.
----------------------------------------------------------------------
Comment By: Karl Waclawek (kwaclaw)
Date: 2003-02-25 10:44
Message:
Logged In: YES
user_id=290026
Expat only supports XML Namespaces 1.0, but the bug
still applies (section 5.3 of the spec).
Will look into it.
Does this happen with previous versions of Expat?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=110127&aid=692964&group_id=10127
More information about the Expat-bugs
mailing list