Skip to content

xmlLoadString is stricter than xmlLoadFile when parsing loose attributes (e.g., <meta oop>) #5180

Description

@99Cengizhan

Describe the bug

There is an inconsistency in how the XML parser handles improperly formatted XML depending on which function is used.

When loading community-generated maps or meta files, it is common to encounter loose or invalid XML attributes such as (missing the boolean value) or (undeclared namespace).

If you load these files using xmlLoadFile, the parser handles them gracefully and successfully creates the XML node. However, if you read the exact same file contents into a string and use xmlLoadString, the parsing fails and returns false.

Steps to reproduce

  1. Create a file named test.xml with the following content:
<meta oop>
    <info author="test" />
</meta>
  1. Run the following Lua code:
-- 1. Testing xmlLoadFile (Works)
local xmlFile = xmlLoadFile("test.xml")
if xmlFile then
    outputDebugString("xmlLoadFile: SUCCESS")
    xmlUnloadFile(xmlFile)
else
    outputDebugString("xmlLoadFile: FAILED")
end

-- 2. Testing xmlLoadString (Fails)
local file = fileOpen("test.xml")
local size = fileGetSize(file)
local rawXML = fileRead(file, size)
fileClose(file)

local xmlString = xmlLoadString(rawXML)
if xmlString then
    outputDebugString("xmlLoadString: SUCCESS")
    xmlUnloadFile(xmlString)
else
    outputDebugString("xmlLoadString: FAILED")
end

Expected behavior:
xmlLoadString should have the same fault tolerance as xmlLoadFile. Both functions should ideally be able to parse the same XML structures, especially since xmlLoadString is often needed for custom map loaders or when decrypting downloaded XML files in memory.

Actual behavior:
xmlLoadFile returns the XML node, while xmlLoadString returns false.

Version

Server: v1.6-release-24133

Additional context

No response

Relevant log output

Security Policy

  • I have read and understood the Security Policy and this issue is not security related.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions