gisle/html-parser — pull request #4 by demerphq (2013-03-25 16:20:25+00:00)
Title: Fix Issue #3 / RT #84144: HTML::Entities::decode_entities() needs to call SV_CHECK_THINKFIRST() before checking READONLY flag

Later versions of Perl have added or changed meanings of various flags. In
particular keys in 5.12 and 5.14 have READONLY+FAKE flags set, which is supposed
to mean "PV is readonly but SV is not", and is supposed to be handled by calling
sv_force_normal_flags() on the SV before operating on it. Bleadperl
changes this to an "IsCOW" flag.

In order to future proof against these kinds of changes it is important
to call SV_CHECK_THINKFIRST() before inspecting the SV. This ensures
that sv_force_normal_flags() is called if needed.

The end result is that HTML::Entities::decode_entities() can handle
arguments obtained from keys() without choking. A minor inconvenience is
that this changes the error message from

decode_entities("string literal")

from

Can't inline decode readonly string

to

Modification of a read-only value attempted

which seems an acceptable cost to pay. I do not know of any backwards
compatible way of checking the flags to both respect the SvTHINKFIRST
macros AND make it possible trap a "true" readonly value. I think
that will require future changes to Perl itself.

This patch includes some new tests to ensure keys() are ok in
decode_entities().