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

Fixed numeric html attributes being discarded #921

Closed
wants to merge 1 commit into from

Conversation

php4fan
Copy link

@php4fan php4fan commented May 2, 2020

I've just encountered this bug, I don't know if there's a bug report about it.

Before this change, tag_attributes() would silently discard all attributes with numeric values unless the values were passed as string.
For example:

tag_attributes(['width'=>300, 'height'=>200, 'foo'=>'bar'];
// expected result: 'width="300" height="200" foo="bar"'
// actual result before fix: 'foo="bar"'

tag_attributes(['width'=>'300', 'height'=>'200', 'foo'=>'bar'];  // this would already work as expected

As a consequence:

record_image($someRecord, null, ['width'=>300, 'height'=>200]);

would result in an image tag without the expected width and height attributes.

I've just encountered this bug, I don't know if there's a bug report about it.

Before this change, `tag_attributes()` would silently discard all attributes with numeric values unless the values were passed as string.
For example:
```
tag_attributes(['width'=>300, 'height'=>200, 'foo'=>'bar'];
// expected result: 'width="300" height="200" foo="bar"'
// actual result before fix: 'foo="bar"'

tag_attributes(['width'=>'300', 'height'=>'200', 'foo'=>'bar'];  // this would already work as expected
```

As a consequence:
```
record_image($someRecord, null, ['width'=>300, 'height'=>200]);
```
would result in an image tag without the expected width and height attributes.
@zerocrates
Copy link
Member

This looks like a fine change to me...

There's a couple minor matters of code style: we would include the technically-unnecessary curly braces for your one-line if (turning it into a three-liner), and I think a cast to string is clearer than the construct you're using here.

Also, a very quick testcase for this would be appreciated (tag_attributes has an existing test class at application/tests/suite/Helpers/TagAttributesTest.php).

@php4fan
Copy link
Author

php4fan commented May 4, 2020

Feel free to redo the changes from scratch if it's more convenient than merging this pull request.

It just felt easier to create the PR than to open an issue for what seemed to be a one-liner

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 this pull request may close these issues.

2 participants