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

Attribute parsing should return true when attribute is set without value #3

Closed
danielbachhuber opened this issue Jun 15, 2018 · 4 comments

Comments

@danielbachhuber
Copy link

Given an HTML element:

<audio src="#" loop>

When I parse the loop attribute on the element, the value should be true:

it( 'should return true if the attribute is set without value', () => {
	const result = parse( element, attr( 'audio', 'loop' ) );

	expect( result ).to.be.true;
} );

parse() currently returns undefined.

From WordPress/gutenberg#7322 (comment)

@danielbachhuber
Copy link
Author

Debugging this further, prop( selector, 'attributes' )( node ) is returning undefined for <audio loop>

@aduth
Copy link
Owner

aduth commented Jun 18, 2018

As low-level as hpq is meant to be, I don't know that true should necessarily be the expected return value, as this requires some understanding of boolean attributes, which I'm not strictly opposed to, but adds some complexity/maintenance burden to the library. That said, undefined is not expected. I would expect, based on hpq's reliance on one or other of Element#attributes or Element#getAttribute, that it should at least be the empty string.

var wrapper = document.createElement( 'div' );
wrapper.innerHTML = '<audio loop>';
var audio = wrapper.querySelector( 'audio' );
console.log( audio.getAttribute( 'loop' ) );
// ""
console.log( audio.attributes.loop.value );
// ""

@danielbachhuber
Copy link
Author

Huh. Anyways, I got stuck on trying to figure out why prop( selector, 'attributes' )( node ) returned undefined, when I expected it to return an object.

@aduth
Copy link
Owner

aduth commented Jun 25, 2018

It was a small mistake with the test changes in #4, where the element was not including the added markup since the additional markup was defined outside the root blockquote. With patch at #4 (comment), attr( 'audio', 'loop' ) returns the empty string as expected.

@aduth aduth closed this as completed Jun 25, 2018
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