You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It doesn't take into account if the prefix is an empty string. If it's an empty string, it should not be getting the namespace from a parent with an empty prefix, as that will always fail the requirement of having the closing tag with the same namespace, as the prefix is empty, and it will be empty on the closing tag too.
If an element has no prefix, then it will end up getting a random namespace from a parent if any parent doesn't have a prefix either. For this reason, I imagine this can't be desired behavior. Also, if we keep class B with a prefix, the issue is that if the xml string you are trying to decode doesn't provide a prefix on the ElementB tag, it still fails, and we don't have control over the xml string that could come from third parties, which is my case.
If it is strongly felt that this really is the desired behavior, then the requirement on the ending tag should be that its prefix is the same as its starting element's prefix, and not the namespace.
The text was updated successfully, but these errors were encountered:
There is actually an encoding error in the first example. The second element needs xmlns=... and the third element needs xmlns="" (although it is not clear that this is valid, the null namespace is only for compatibility)
The
KtXmlReader
incorrectly handles namespace and prefixes in the case where the prefix is empty. This very simple example shows the problem.When running this,
dataString
looks like this after encoding:And when decoding, it throws this exception:
Namespace namespace/b does not match expected ""
If we change class B to look like this:
then the encoded string now looks like this:
and decoding works properly.
The issue is in NamespaceHolders's
getNamespaceUri()
function:It doesn't take into account if the prefix is an empty string. If it's an empty string, it should not be getting the namespace from a parent with an empty prefix, as that will always fail the requirement of having the closing tag with the same namespace, as the prefix is empty, and it will be empty on the closing tag too.
If an element has no prefix, then it will end up getting a random namespace from a parent if any parent doesn't have a prefix either. For this reason, I imagine this can't be desired behavior. Also, if we keep class B with a prefix, the issue is that if the xml string you are trying to decode doesn't provide a prefix on the ElementB tag, it still fails, and we don't have control over the xml string that could come from third parties, which is my case.
If it is strongly felt that this really is the desired behavior, then the requirement on the ending tag should be that its prefix is the same as its starting element's prefix, and not the namespace.
The text was updated successfully, but these errors were encountered: