NaturalIntelligence / fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback.
https://naturalintelligence.github.io/fast-xml-parser/
MIT License
2.45k stars 296 forks source link

Uncaught TypeError: Assignment to constant variable #551

Closed srinivas-gangji closed 1 year ago

srinivas-gangji commented 1 year ago

Description

Running latest version causes below error ``` Uncaught TypeError: Assignment to constant variable. at h (validator.js:399:1) at C2Vs.t.validate (validator.js:121:1) ``` I think that the issue is caused due to the 'const' assignment in validator.js ```js } else { const isValid = validateAttributeString(attrStr, options); if (isValid !== true) { //the result from the nested function returns the position of the error within the attribute //in order to get the 'true' error line, we need to calculate the position where the attribute begins (i - attrStr.length) and then add the position within the attribute //this gives us the absolute index in the entire xml, which we can use to find the line at last return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line)); } ``` ### Input

Using version 4.1.3

Code

  let result = XMLValidator.validate(xsltValue, {
          allowBooleanAttributes: true
        })

Output

expected data

Would you like to work on this issue?

Bookmark this repository for further updates.

github-actions[bot] commented 1 year ago

I'm glad you find this repository helpful. I'll try to address your issue ASAP. You can watch the repo for new changes or star it.

amitguptagwl commented 1 year ago

Can you please share the sample XML?

srinivas-gangji commented 1 year ago

@amitguptagwl After spending sometime validating from my end, I am observing that this error occurs when I am validating below xml

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fn="http://www.w3.org/2005/xpath-functions" version="2.0">
</xsl:stylesheet>

Note : Please note that his only happens on production build ( i.e minified version of the library, using development build, doesn't produce any errors)

srinivas-gangji commented 1 year ago

Update : @amitguptagwl I was able to resolve my issue by moving the validation mechanism to nodejs.

amitguptagwl commented 1 year ago

okay