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

html5 method eating attribute value when value is eq to name #777

Closed
christophe-g opened this issue Sep 7, 2015 · 8 comments · Fixed by #1933
Closed

html5 method eating attribute value when value is eq to name #777

christophe-g opened this issue Sep 7, 2015 · 8 comments · Fixed by #1933
Labels
enhancement new features, suggestions, etc.

Comments

@christophe-g
Copy link

With very recent build on develop branch,

xquery version "3.0";

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "html5";

<html>
    <div test="test">Hello</div>
</html>

will return

<html>
    <div test>Hello</div>
</html>

This causes the browser to report

This page contains the following errors:

error on line 3 at column 13: Specification mandate value for attribute test
Below is a rendering of the page up to the first error.

... and the wiki app to behave strangely as some parameter will never be sent to the server, like name in :

 <input class="form-control" data-template="app:edit-name" type="text" name="name" placeholder="ShortName" required="required" pattern="[A-Za-zäöüÄÖÜ]{1}[\w-äöüßÄÖÜ]{2,}"/>

C.

@christophe-g
Copy link
Author

@wolfgangmm... just before it disappears on page 2, can it be confirmed as a bug ?
Cheers,
C.

@wolfgangmm
Copy link
Member

Well, I guess the HTML5 serialiser needs a list of attributes which can be empty (e.g. "disabled") and should thus be collapsed. All other attributes should be preserved. I have not found such a list yet though.

@joewiz
Copy link
Member

joewiz commented Oct 2, 2015

According to the HTML5 spec on boolean attributes (see also the WHATWG version), <div test="test"> is absolutely equivalent to <div test>. I think eXist's HTML5 serializer is correct.

My question is: what is responsible for issuing the error, "Specification mandate value for attribute test"? Is it the browser (if so, which?) or some script running in the page (if so, is there an HTML5-compatible version?)?

@christophe-g
Copy link
Author

@joewiz Agreed (and thanks for the refs), but in this specific case, test is not a boolean attribute.
@wolfgangmm Should really test="test", name="name" or data-keepme="data-keepme" attributes be collapsed under html5 serialization?

There are 2 problems here :

  • the actual string value of the attribute disappears. In the following, the submission data a server will receive are not equivalent.
    Consider
<form action="submit.xql">
  Name: <input type="text" name="name"><br>
  <input type="submit" value="Submit">
</form>

parsed as (without value name as it is the case in the wiki) :

<form action="submit.xql">
  Name: <input type="text" name><br>
  <input type="submit" value="Submit">
</form>
  • Apparently the markup is malformed (error reported on Chrome 45 - htm5 compliant)

@joewiz
Copy link
Member

joewiz commented Oct 2, 2015

Here's a list of boolean attributes drawn from the spec:

kangax/html-minifier#63 (comment)

Since that list might be out of date, I've applied the same methodology to produce an up to date list from the current HTML 5.1 spec:

xquery version "3.0";

declare namespace html="http://www.w3.org/1999/xhtml";

import module namespace http="http://expath.org/ns/http-client";

<results>{
    let $url := "http://www.w3.org/TR/html51/single-page.html"
    let $request := <http:request href="{$url}" method="get"/>
    let $response-body := http:send-request($request)[2]
    let $hits := $response-body//text()[contains(., 'attribute boolean')]/following-sibling::html:a[1]
    for $attribute in distinct-values($hits)
    order by $attribute
    return
        <result>{$attribute}</result>
}</results>

Results:

<results>
    <result>allowFullscreen</result>
    <result>async</result>
    <result>autofocus</result>
    <result>autoplay</result>
    <result>badInput</result>
    <result>checked</result>
    <result>closed</result>
    <result>commandChecked</result>
    <result>commandDisabled</result>
    <result>commandHidden</result>
    <result>compact</result>
    <result>complete</result>
    <result>controls</result>
    <result>cookieEnabled</result>
    <result>customError</result>
    <result>declare</result>
    <result>default</result>
    <result>defaultChecked</result>
    <result>defaultMuted</result>
    <result>defaultSelected</result>
    <result>defer</result>
    <result>disabled</result>
    <result>draggable</result>
    <result>enabled</result>
    <result>ended</result>
    <result>formNoValidate</result>
    <result>hidden</result>
    <result>indeterminate</result>
    <result>isContentEditable</result>
    <result>isMap</result>
    <result>itemScope</result>
    <result>javaEnabled</result>
    <result>loop</result>
    <result>multiple</result>
    <result>muted</result>
    <result>noHref</result>
    <result>noResize</result>
    <result>noShade</result>
    <result>noValidate</result>
    <result>noWrap</result>
    <result>onLine</result>
    <result>open</result>
    <result>patternMismatch</result>
    <result>pauseOnExit</result>
    <result>paused</result>
    <result>persisted</result>
    <result>rangeOverflow</result>
    <result>rangeUnderflow</result>
    <result>readOnly</result>
    <result>required</result>
    <result>reversed</result>
    <result>scoped</result>
    <result>seamless</result>
    <result>seeking</result>
    <result>selected</result>
    <result>sortable</result>
    <result>spellcheck</result>
    <result>stepMismatch</result>
    <result>tooLong</result>
    <result>tooShort</result>
    <result>translate</result>
    <result>trueSpeed</result>
    <result>typeMismatch</result>
    <result>typeMustMatch</result>
    <result>valid</result>
    <result>valueMissing</result>
    <result>visible</result>
    <result>willValidate</result>
</results>

@devatwork
Copy link
Contributor

I just hit this issue by following the steps described at http://www.exist-db.org/exist/apps/doc/development-starter which is kind of confusing for first-time developers using the evolvedbinary/exist-db:eXist-5.0.0-RC1-minimal Docker image. It would be good to fix this bug. If not possible, at the very least document the behavior and change the tutorial to work around this issue.

@devatwork
Copy link
Contributor

Just took a quick look at the source code and the problem seems to be at https://github.com/eXist-db/exist/blob/develop/src/org/exist/util/serializer/HTML5Writer.java#L103

Would you be open to a PR implementing a check on the boolean whitelist as reported by @joewiz?

@duncdrum
Copy link
Contributor

@devatwork thanks for taking a look at this, PRs with fixes are always welcome. When you open the PR could you please indicate if the documentation is now working as expected or include any necessary adjustments in a separate PR at the docs

@duncdrum duncdrum added enhancement new features, suggestions, etc. needs documentation Signals issues or PRs that will require an update to the documentation repo labels Jun 12, 2018
devatwork added a commit to devatwork/exist that referenced this issue Jun 12, 2018
This change fixes two problems:
1. The attribute name is not written at all if its value is equal. Happened only in the HTML5Writer.attribute(QName, String) function
2. Only omit the values which are equal to the attribute name for attributes that are considered boolean according to the HTML 5.1 spec

Fixes eXist-db#777
@duncdrum duncdrum removed the needs documentation Signals issues or PRs that will require an update to the documentation repo label Jun 13, 2018
adamretter pushed a commit to adamretter/exist that referenced this issue Jun 13, 2018
This change fixes two problems:
1. The attribute name is not written at all if its value is equal. Happened only in the HTML5Writer.attribute(QName, String) function
2. Only omit the values which are equal to the attribute name for attributes that are considered boolean according to the HTML 5.1 spec

Fixes eXist-db#777
adamretter pushed a commit to adamretter/exist that referenced this issue Jun 13, 2018
This change fixes two problems:
1. The attribute name is not written at all if its value is equal. Happened only in the HTML5Writer.attribute(QName, String) function
2. Only omit the values which are equal to the attribute name for attributes that are considered boolean according to the HTML 5.1 spec

Fixes eXist-db#777
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new features, suggestions, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants