Skip to content

Determine Page Encoding from Meta Tag #138

@kevingy

Description

@kevingy

As discussed in Issue #136, SimpleBrowser currently only sets the page encoding if the character set is specified in the Content-Type HTTP header. If the Content-Type HTTP header specifies the character set, this is the correct behavior and this value should be used. If it is not set in the Content-Type HTTP header, the character set may be specified in HTML:

HTML 4.01: <meta http-equiv="content-type" content="text/html; charset=UTF-8">
HTML5: <meta charset="UTF-8">
XHTML: <?xml version="1.0" encoding="utf-8"?>

See the HTML5 Specification on this topic:
http://www.w3.org/TR/html5/document-metadata.html#character-encoding-declaration

Notes:

  1. Implementing this change will require pre-processing (parsing) the first 1K of the received HTML. To improve performance, this code should NOT be executed if the Content-Type specifies the content type.
  2. Pre-parsing HTML to determine the character set should not change how parsing the main HTML content works. Currently, HTML is not parsed until the first call to Find(). This is desirable behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions