]> granicus.if.org Git - php/commit
- Completed rewrite of html.c. Except for determine_charset, almost nothing
authorGustavo André dos Santos Lopes <cataphract@php.net>
Sun, 24 Oct 2010 15:01:02 +0000 (15:01 +0000)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Sun, 24 Oct 2010 15:01:02 +0000 (15:01 +0000)
commit91727cb844ecfe55f6dcd2f13ffeec3962aabbac
tree23a66a5e5d2565be626cf00965ac035f757894fe
parentf0d2559d2649854433ac42869744df3c2f05b6c8
- Completed rewrite of html.c. Except for determine_charset, almost nothing
  remains.
- Fixed bug on determine_charset that was preventing correct detection in
  combination with internal mbstring encoding "none", "pass" or "auto".
- Added profiles for entity encode/decode for HTMl 4.01, XHTML 1.0, XML 1.0
  and HTML 5. Added the constants ENT_HTML401, ENT_XML1, ENT_XHTML and
  ENT_HTML5.
- htmlentities()/htmlspecialchars(), when told not to double encode, verify
  the correctness of the existenting entities more thoroughly.
  It is checked whether the numerical entity represents a valid unicode code
  point (number is between 0 and 0x10FFFF). If using the flag ENT_DISALLOWED,
  it is also checked whether that numerical entity is valid in selected
  document. In HTML 4.01, all the numerical entities that represent a Unicode
  code point (< U+10FFFFFF) are valid, but that's not the case with other
  document types. If the entity is not valid, & is encoded to &amp;.
  For named entities, the check is also more thorough. While before the only
  check would be to determine if the entity was constituted by alphanumeric
  characters, now it is checked whether that entity is necessarily defined for
  the target document type. Otherwise, & is encoded to &amp;.
- For html_entity_decode(), only valid numerical and named entities (as defined
  above for htmlentities()/htmlspecialchars() + !double_encode) are decoded.
  But there is in this case one additional check. Entities that represent
  non-SGML or otherwise invalid characters are not decoded. Note that, in
  HTML5, U+000D is a valid literal character, but the entity &#x0D is not
  valid and is therefore not decoded.
- The hash tables lazily created for decoding in html_entity_decode() that were
  added recently were substituted by static hash tables. Instead of 1 hash
  table per encoding, there's only one hash table per document type defined in
  terms of unicode code points. This means that for charsets other than UTF-8
  and ISO-8859-1, a conversion to unicode code points is necessary before
  decoding.
- On the encoding side, the ad hoc ranges of entities of the translation
  tables, which mapped (in general) non-unicode code points to HTML entities
  were replaced by three-stage tables for HTML 4 and HTML 5. This mapping
  tables are defined only in terms of unicode code points, so a conversion
  is necessary for charsets other than UTF-8 and ISO-8859-1. Even so, the
  multi-stage table is much faster than the previous method, by a factor
  of 5; the conversion to unicode is a small penalty because it's just a
  simple table lookup.
  XML 1.0/htmlspecialchars() uses a simple table instead of a three-stage
  table.
- Added the flag ENT_SUBSTITUTE, which makes htmlentities()/htmlspecialchars()
  replace the invalid multibyte sequences with U+FFFD (UTF-8) or &#FFFD;
  (other encodings).
- Added the flag ENT_DISALLOWED. Implements FR #52860. Characters that cannot
  appear literally are replaced by U+FFFD (UTF-8) or &#FFFD; (otherwise).
  An alternative implementation would be to encode those characters into
  numerical entities, but that would only work in HTML 4.01 due to limitations
  on the values of numerical entities in other document types. See also the
  effects on htmlentities()/htmlspecialchars() with !double_encode above.
47 files changed:
ext/standard/basic_functions.c
ext/standard/basic_functions.h
ext/standard/html.c
ext/standard/html.h
ext/standard/html_tables.h
ext/standard/html_tables/ents_basic.txt [new file with mode: 0644]
ext/standard/html_tables/ents_basic_apos.txt [new file with mode: 0644]
ext/standard/html_tables/ents_html401.txt [new file with mode: 0644]
ext/standard/html_tables/ents_html5.txt [new file with mode: 0644]
ext/standard/html_tables/ents_xhtml.txt [new file with mode: 0644]
ext/standard/html_tables/html_table_gen.php [new file with mode: 0644]
ext/standard/html_tables/mappings/8859-1.TXT [new file with mode: 0644]
ext/standard/html_tables/mappings/8859-15.TXT [new file with mode: 0644]
ext/standard/html_tables/mappings/8859-5.TXT [new file with mode: 0644]
ext/standard/html_tables/mappings/CP1251.TXT [new file with mode: 0644]
ext/standard/html_tables/mappings/CP1252.TXT [new file with mode: 0644]
ext/standard/html_tables/mappings/CP866.TXT [new file with mode: 0644]
ext/standard/html_tables/mappings/KOI8-R.TXT [new file with mode: 0644]
ext/standard/html_tables/mappings/ROMAN.TXT [new file with mode: 0644]
ext/standard/tests/strings/bug49785.phpt
ext/standard/tests/strings/get_html_translation_table_basic1.phpt
ext/standard/tests/strings/get_html_translation_table_basic2.phpt
ext/standard/tests/strings/get_html_translation_table_basic3.phpt
ext/standard/tests/strings/get_html_translation_table_basic4.phpt
ext/standard/tests/strings/get_html_translation_table_basic5.phpt [new file with mode: 0644]
ext/standard/tests/strings/get_html_translation_table_basic6.phpt [new file with mode: 0644]
ext/standard/tests/strings/get_html_translation_table_basic7.phpt [new file with mode: 0644]
ext/standard/tests/strings/get_html_translation_table_basic8.phpt [new file with mode: 0644]
ext/standard/tests/strings/get_html_translation_table_basic9.phpt [new file with mode: 0644]
ext/standard/tests/strings/get_html_translation_table_variation1.phpt
ext/standard/tests/strings/html_entity_decode1.phpt [new file with mode: 0644]
ext/standard/tests/strings/html_entity_decode2.phpt [new file with mode: 0644]
ext/standard/tests/strings/html_entity_decode3.phpt [new file with mode: 0644]
ext/standard/tests/strings/html_entity_decode_cp866.phpt
ext/standard/tests/strings/html_entity_decode_html4.phpt
ext/standard/tests/strings/html_entity_decode_html5.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlentities13.phpt
ext/standard/tests/strings/htmlentities14.phpt
ext/standard/tests/strings/htmlentities16.phpt
ext/standard/tests/strings/htmlentities18.phpt
ext/standard/tests/strings/htmlentities19.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlentities20.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlentities21.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlentities22.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlentities23.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlentities_html5.phpt [new file with mode: 0644]
ext/standard/tests/strings/htmlspecialchars_decode_variation7.phpt [new file with mode: 0644]