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

Error on load caused by unrecognized script tag #282

Closed
ChristopheDeBernardi opened this issue Feb 9, 2022 · 4 comments · Fixed by #294
Closed

Error on load caused by unrecognized script tag #282

ChristopheDeBernardi opened this issue Feb 9, 2022 · 4 comments · Fixed by #294

Comments

@ChristopheDeBernardi
Copy link

ChristopheDeBernardi commented Feb 9, 2022

Important:

I'm using the 1.0.3 release because it seems that newer versions do not work well with ESEF reports (but that's another issue).
I don't think the version difference is related with my current problem but it's worth mentioning.


Description

In certain conditions opening the viewer gives a Could not find viewer data error.
Unfortunately I was not able to determine the root cause of the issue nor can I provide the relevant iXBRL instance, because it is an actual financial report which may not be public yet.

image

However I found out that the data is not detected because the <script> tag enclosing the JSON data is actually prefixed with the xhtml namespace:

image

I thought this was because this prefix is explicitly defined in the report...

image

... but I was not able to reproduce the problem that way.

(Edit: I tried creating a viewer after removing that xhtml namespace prefix declaration from the original report and it worked, so I guess that is the problem after all.
Still this case could be addressed.)

I suppose the problem could be fixed either when the viewer is created in Arelle...

image

... or in the javascript during the lookup for the <script type="application/x.ixbrl-viewer+json"> (maybe by looking at the localName rather than the tagName?):

image

image


Miscellaneous

I mentionned two people in the issue for review (because the last one I wrote is still open ;) ), I hope that's ok.

review:
@derekgengenbacher-wf @sagesmith-wf

@paulwarren-wk
Copy link
Contributor

What browser are you using, and how are you accessing the file? Is it behind a web server, and what file extension does it have? The fact that this is happening makes me think that it's being treated as HTML rather than XHTML.

We should still try to fix it, as we try to make the viewer work in both HTML and XHTML modes.

@ChristopheDeBernardi
Copy link
Author

  • I reproduced the issue with Firefox and Chrome
  • The original problem occurred while serving the XHTML file from a web server, but I reproduced it by opening a file from my PC, with the javascript file also available locally
  • The file has an .xhtml extension

After further tests I managed to create this iXBRL instance that triggers this issue. (It's a report package derived from the ESEF conformance suite 2021)

As I suspected, the problem is caused by a namespace prefix, but the position of the declaration is important.
For instance the following structure will cause the problem:

image

But this one where the order of lines is different will not:

image

@paulwarren-wk
Copy link
Contributor

I've confirmed that the order of the namespace declarations does seem to be important here. It appears that lxml uses the first prefix it finds for a given namespace when choosing which prefix to use for newly created elements, and there does not appear to be anyway to override this.

Switching to localName rather than tagName will fix this particular problem, but there's a related problem which is that if the <script> tag which references the viewer JS gets included as <xhtml:script> the viewer won't load at all of if the document gets loaded in HTML mode.

@paulwarren-wk
Copy link
Contributor

I think I have found a way. If we use SubElement() rather than Element() then append(), it seems to respect our namespace prefix preferences:

from lxml import etree

xml='''
<a:foo 
xmlns:a="https://www.example.com"
xmlns="https://www.example.com" 
>
</a:foo>
'''

x = etree.fromstring(xml)

e = etree.Element("{https://www.example.com}script", nsmap = { None: 'https://www.example.com' })
x.append(e)
print("Create then append: " + str(e.prefix))

e = etree.SubElement(x, '{https://www.example.com}script', nsmap = { None: 'https://www.example.com' })
print("Sub element: " + str(e.prefix))

print(etree.tostring(x, method="xml", xml_declaration=True, pretty_print=True).decode())

Produces:

Create then append: a
Sub element: None
<?xml version='1.0' encoding='ASCII'?>
<a:foo xmlns:a="https://www.example.com" xmlns="https://www.example.com">
<a:script/><script/></a:foo>

paulwarren-wk pushed a commit to paulwarren-wk/ixbrl-viewer that referenced this issue Apr 10, 2022
rmconsole4-wk added a commit that referenced this issue Apr 11, 2022
…space-bug

Ensure that <script> tags always use default namespace (#282)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants