#16432 closed enhancement (fixed)
Add filter to ent2ncr
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.3 |
| Component: | General | Version: | 3.1 |
| Severity: | minor | Keywords: | has-patch commit |
| Cc: |
Description
There's been several tickets regarding the use of hexadecimal numerical entities instead of decimal numerical entities - it's part of a W3C standard that Content SHOULD use the hexadecimal form of character escapes rather than the decimal form when there are both.
This patch adds hexadecimal entity support to ent2ncr() for the existing named entities. It adds an optional second argument, and defaults to returning the decimal entities so is fully backwards compatible.
Attachments (5)
Change History (19)
If there's a better performing way to pull out the entities from the $to_ncr array that having to loop through and pull them into a new array first, then please let me know!
I thought about creating two arrays ($to_ncr and $to_hncr), but then figured the sets of named entities may get out of sync. If there's not much change in this function it may be fine to do that.
Alternatively, an ent2hncr() function may be better, which ent2ncr defers to if the 2nd argument is correctly set?
Should is not Must.
I think a better solution is just to add a filter to this function so a plugin can implement the alternative behaviour.
- Keywords needs-testing added
Two patches - the first is a simple filter on the return value.
The second patch approaches it a slightly different way. The issue with the first, is that for a block of text that is being running through ent2ncr(), all of the string replacements would still be done, even if they weren't then used in the plugin filter function. By letting the plugin short circuit the function (if something truthy is being returned from the plugin filter function, return that from ent2ncr() immediately), it improves performance.
- Summary changed from Hexadecimal entity support within ent2ncr to Add filter to ent2ncr
Is it too late for this filter to go in to 3.2?
- Keywords needs-testing removed
- Milestone changed from Awaiting Review to Future Release
Yes. Freeze for enhancements was about 6 weeks ago.
Wasn't aware you could do a comparison against an assignment like that - handy! Patched.
comment:10
nacin — 22 months ago
- Keywords commit added
- Milestone changed from Future Release to 3.3
comment:11
follow-up:
↓ 12
nacin — 22 months ago
- Owner set to nacin
- Resolution set to fixed
- Status changed from new to closed
In [18456]:
comment:12
in reply to:
↑ 11
westi — 22 months ago
- Resolution fixed deleted
- Status changed from closed to reopened
comment:13
westi — 22 months ago
- Resolution set to fixed
- Status changed from reopened to closed
In [18465]:
comment:14
scribu — 22 months ago
+1 for [18465]. Just because you can doesn't mean you should.

Adds hexadecimal entity support to ent2ncr()