You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Chow, Crandall" <cc...@vignette.com> on 2000/12/04 05:15:00 UTC

bug in DefaultEntityHandler.startReadingFromExernalEntity()?

I've been playing with Arbortext's catalog entity resolver, and noticed
there's a possible bug in 'DefaultEntityHandler.java' (Xerces-J 1.2.2).  The
method is 'startReadingFromExternalEntity()'.  Line 749 has a call to
'expandSystemId()' before passing it on to a potential 'resolveEntity()' on
the following line.  I believe this is incorrect, since the system ID may
now have the base directories and 'file:///' proto that the catalog resolver
may not be expecting.  Here's an example:

CATALOG FILE
------------
SYSTEM "fake.dtd" "docs/real.dtd"

XML DOC
-------
<!DOCTYPE head SYSTEM "fake.dtd">

Using a catalog entity resolver, this should work just fine, as the system
ID "fake.dtd" is eventually mapped to "docs/real.dtd".  (By the way, it
could also be mapped to a true URI, such as "file:///e:/docs/real.dtd", but
that's not a big deal in this example.)  In this case,
DefaultEntityHandler.startReadingFromExternalEntity() will be called during
the parse to try and resolve the system ID "fake.dtd", before assuming it's
a straight URI.  The code as it sits will turn the ID "fake.dtd" into a tru
URI, such as "file:///e:/some_base/fake.dtd" before passing it onto the
'resolveEntity()' method of our entity resolver.  Obviously, there is no map
to this expanded system ID in the catalog, so the resolution will fail.
This appears to not be the desired behavior, especially since the catalog
author would never know the base directories prior to a given parse.
Instead, I believe the code should appear similar to:

        if (baseSystemId == null) {
            ReaderState rs = (ReaderState) fReaderStack.peek();
            baseSystemId = rs.systemId;
        }
        fSource = fResolver == null ? null :
fResolver.resolveEntity(fPublicId, fSystemId);
        if (fSource == null) {
	    fSystemId = expandSystemId(fSystemId, baseSystemId);
            fSource = new InputSource(fSystemId);

where the 'expandSystemId()' line is moved from line 749 into the 'if'
statement at line 751.

Can someone please confirm or reject this?  Who is the person in control of
this file in case a change is needed?  Thanks folks.

  -crandall

Crandall Chow (cchow@vignette.com)
Vignette Corporation--Austin, Texas