Skip to content

PiDirective lowercases the PI target, dropping case in violation of the XML spec #320

Description

@edmoffo

The constructor of PiDirective lowercases the target name with tgt.toLowerCase(Locale.ENGLISH) before storing it in this.target, see src/main/java/org/xembly/PiDirective.java around line 38. The lowercased value is later used in Document.createProcessingInstruction(this.target.raw(), this.data.raw()) around line 60, so the case information from the caller is lost in the produced DOM.

XML 1.0 Names are case-sensitive, and the PITarget production in section 2.6 inherits that. Calling new Directives().pi("MyApp", "x") ends up emitting <?myapp x?> instead of <?MyApp x?>, which is observably different from what every other XML toolchain produces for the same input. Callers that expect the target they wrote to round-trip through xembly silently get a different document.

The lowercasing looks like it was meant to detect the reserved xml prefix (case-insensitive per the spec), but storing the lowercased form goes further than that and rewrites the user input. The fix is to keep tgt as-is in this.target and, if a check is still wanted, reject targets that match (?i)^xml$ instead of folding the case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions