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

Comparing node names should be case insensitive #32

Closed
gertsonderby opened this issue Oct 2, 2015 · 11 comments
Closed

Comparing node names should be case insensitive #32

gertsonderby opened this issue Oct 2, 2015 · 11 comments

Comments

@gertsonderby
Copy link

Different platforms variously use upper- or lower-case names for nodes, for the purpose of comparison. An example:

<div>
    <p>Text and things.</p>
</div>

The above is used as subject, below:

expect(subject, 'to satisfy', {
    name: 'div',
    children: [ { name: 'p' } ]
});

In Chrome, the above will work. In IE, it will fail, as it does not recognize that 'div' as equal to 'DIV'.

@gertsonderby
Copy link
Author

It appears that Chrome, Firefox and Opera use lower-case, IE/Edge and Safari use uppercase.

@papandreou
Copy link
Member

Weird, it should already be lower casing before comparing when it's an HTML document. Maybe that detection code (element.ownerDocument.contentType === 'text/html') isn't working properly.

@gertsonderby Could you check what that comes out as in the browsers that exhibit the problem?

@gertsonderby
Copy link
Author

In IE11 and Safari 8 both, document.contentType is undefined.

@gertsonderby
Copy link
Author

https://developer.mozilla.org/en-US/docs/Web/API/Document/contentType

Apparently the feature is non-standard. Not too sure how then to solve it.

@papandreou
Copy link
Member

@gertsonderby Aha!

Could you check what new DOMParser().parseFromString('<foo></foo>', 'text/xml').firstChild.ownerDocument.contentType evaluates to?

@papandreou
Copy link
Member

Falling back to element.ownerDocument.toString() === '[object HTMLDocument]' might work (at least I get [object XMLDocument] for XML documents in Chrome).

@gertsonderby
Copy link
Author

That yields undefined, yet again, for IE.The result is the same for Safari.

@gertsonderby
Copy link
Author

In Safari:

> new DOMParser().parseFromString('<foo></foo>', 'text/xml').firstChild.ownerDocument.toString()
< "[object Document]"
> new DOMParser().parseFromString('<foo></foo>', 'text/html').firstChild.ownerDocument.toString()
< "[object HTMLDocument]"

@papandreou
Copy link
Member

@gertsonderby Interesting. How about document.toString() in those browsers (from the dev tools when viewing any HTML page)?

@gertsonderby
Copy link
Author

That yields "[object HTMLDocument]", consistently, as far as I can tell.

@papandreou
Copy link
Member

#33

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

No branches or pull requests

2 participants