Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoder shifts prefix and namespace names by one #31

Open
Tomas-Kraus opened this issue Apr 26, 2010 · 4 comments
Open

Decoder shifts prefix and namespace names by one #31

Tomas-Kraus opened this issue Apr 26, 2010 · 4 comments

Comments

@Tomas-Kraus
Copy link
Member

The source of the problem is the built-in xml namespace
http://www.w3.org/XML/1998/namespace.
Those entries are not included in the PREFIX and NAMESPACE NAME tables but
decoder knows that hey are there and that they got assigned index number '1'.
This is described in the spec, point 7.2.21 and 7.2.22.

Example xml:
<prefix1:root xmlns:prefix1="namespace1" xmlns:prefix2="namespace2" >
.... the content...
</prefix1:root>

Example prefix table:
1: xml (This entry is built-in and is not included in the
fastinfoset vocabulary table)
2: prefix1
3: prefix2

The easiest way to explain that is by using SAX decoder so during decoding the
DefaultHandler.startPrefixMapping method:

DefaultHandler.startPrefixMapping (String prefix, String uri)

receives the following notifications:
1. prefix="xml", uri="http://www.w3.org/XML/1998/namespace"
2. prefix="prefix1", uri="namespace1"

instead of receiving:
1. prefix="prefix1", uri="namespace1"
2. prefix="prefix2", uri="namespace2"

So during decoding all the prefixes and namespace names are shifted by one.

This bug can be fixed by replacing Decoder.decodeTableItems(QualifiedNameArray
array, boolean isAttribute) method below:

private void decodeTableItems(QualifiedNameArray array, boolean isAttribute)
throws FastInfosetException, IOException {
for (int i = 0; i < decodeNumberOfItemsOfSequence(); i++) {
final int b = read();

String prefix = "";
int prefixIndex = -1;
if ((b & EncodingConstants.NAME_SURROGATE_PREFIX_FLAG) > 0)

{ prefixIndex = decodeIntegerIndexOnSecondBit(); prefix = _v.prefix._array[prefixIndex - 1]; }

String namespaceName = "";
int namespaceNameIndex = -1;
if ((b & EncodingConstants.NAME_SURROGATE_NAME_FLAG) > 0)

{ namespaceNameIndex = decodeIntegerIndexOnSecondBit(); namespaceName = _v.namespaceName._array[namespaceNameIndex - 1]; }

if (namespaceName == "" && prefix != "")

{ throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.missingNamespace")); }

final int localNameIndex = decodeIntegerIndexOnSecondBit();
final String localName = _v.localName.get(localNameIndex);

QualifiedName qualifiedName = new QualifiedName(prefix,
namespaceName, localName,
prefixIndex, namespaceNameIndex, localNameIndex,
_charBuffer);
if (isAttribute) { qualifiedName.createAttributeValues(_duplicateAttributeVerifier.MAP_SIZE); }
array.add(qualifiedName);
}
}

By the method below (fixed lines are annotated):

private void decodeTableItems(QualifiedNameArray array, boolean isAttribute)
throws FastInfosetException, IOException {
for (int i = 0; i < decodeNumberOfItemsOfSequence(); i++) {
final int b = read();

String prefix = "";
int prefixIndex = -1;
if ((b & EncodingConstants.NAME_SURROGATE_PREFIX_FLAG) > 0) { prefixIndex = decodeIntegerIndexOnSecondBit(); // fix for 7.2.21 prefix = _v.prefix._array[prefixIndex - 1]; }

String namespaceName = "";
int namespaceNameIndex = -1;
if ((b & EncodingConstants.NAME_SURROGATE_NAME_FLAG) > 0) { namespaceNameIndex = decodeIntegerIndexOnSecondBit(); // fix for 7.2.22 namespaceName = _v.namespaceName._array[namespaceNameIndex - 1]; }

if (namespaceName == "" && prefix != "") { throw newFastInfosetException(CommonResourceBundle.getInstance().getString("message.missingNamespace")); }

final int localNameIndex = decodeIntegerIndexOnSecondBit();
final String localName = _v.localName.get(localNameIndex);

QualifiedName qualifiedName = new QualifiedName(prefix,
namespaceName, localName,
prefixIndex, namespaceNameIndex, localNameIndex,
_charBuffer);
if (isAttribute)

{ qualifiedName.createAttributeValues(_duplicateAttributeVerifier.MAP_SIZE); }

array.add(qualifiedName);
}
}

Environment

Operating System: All
Platform: All

Affected Versions

[current]

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
Reported by agladkowski

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
Was assigned to oleksiys

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
This issue was imported from java.net JIRA FI-31

@Tomas-Kraus
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants