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

panic: xml: encoding "ISO-8859-1" declared but Decoder.CharsetReader is nil same as #48 #53

Closed
TeoV opened this issue Sep 6, 2018 · 4 comments
Labels

Comments

@TeoV
Copy link

TeoV commented Sep 6, 2018

Hi @beevik
After I done some tests I got same error presented in issue #48
Here is a sample of code + xml data :

var xmlDoc = `<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE broadWorksCDR>
<broadWorksCDR version="19.0">
  <cdrData>
    <headerModule>
      <recordId>
        <eventCounter>0002183384</eventCounter>
        <systemId>CGRateSaabb</systemId>
        <date>20160419210000.104</date>
        <systemTimeZone>1+020000</systemTimeZone>
      </recordId>
      <type>Start</type>
    </headerModule>
  </cdrData>
</broadWorksCDR>
`
doc := etree.NewDocument()
if err := doc.ReadFromBytes([]byte(xmlDoc)); err != nil {
	t.Error(err)
}

First I try to use doc.ReadFromString after doc.ReadFromBytes but got error both times.

Thanks,
TeoV

@TeoV
Copy link
Author

TeoV commented Sep 6, 2018

Hi again @beevik
I found that

doc.ReadSettings.CharsetReader = func(label string, input io.Reader) (io.Reader, error) {
  return input, nil
}

Resolve the problem.
I will let the issue open in case you have another idea.

Thanks,
TeoV

@beevik
Copy link
Owner

beevik commented Sep 6, 2018

I'll try to take a look at this when I get a chance. Thanks for the report, @TeoV.

@beevik beevik added the bug label Sep 6, 2018
@wuzuf
Copy link
Contributor

wuzuf commented Oct 27, 2018

Hi,

Reading the go source code, this seems to be the normal behavior of the default decoder (in xml.go):

if enc != "" && enc != "utf-8" && enc != "UTF-8" && !strings.EqualFold(enc, "utf-8") {
    if d.CharsetReader == nil {
        d.err = fmt.Errorf("xml: encoding %q declared but Decoder.CharsetReader is nil", enc)
       return nil, d.err
   }
[...]

Gabriel

@beevik
Copy link
Owner

beevik commented Oct 27, 2018

This is now fixed in dd07e7c

@beevik beevik closed this as completed Oct 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants