• Show log

    Commit

  • Hash : ec7be506
    Author : Nick Wellnhofer
    Date : 2023-08-08T15:19:46

    parser: Rework encoding detection
    
    Introduce XML_INPUT_HAS_ENCODING flag for xmlParserInput which is set
    when xmlSwitchEncoding is called. The parser can use the flag to
    reliably detect whether an encoding was already set via user override,
    BOM or other auto-detection. In this case, the encoding declaration
    won't be used to switch the encoding.
    
    Before, an inscrutable mix of ctxt->charset, ctxt->input->encoding
    and ctxt->input->buf->encoder was used.
    
    Introduce private helper functions to switch encodings used by both the
    XML and HTML parser:
    
    - xmlDetectEncoding which skips over the BOM, allowing to remove the
      BOM checks from other encoding functions.
    - xmlSetDeclaredEncoding, replacing htmlCheckEncodingDirect, which warns
      about encoding mismatches.
    
    If users override the encoding, store the declared instead of the actual
    encoding in xmlDoc. In this case, the actual encoding is known and the
    raw value from the doc is more useful.
    
    Also use the input flags to store the ISO-8859-1 fallback state.
    Restrict the fallback to cases where no encoding was specified. (The
    fallback is only useful in recovery mode and these days broken UTF-8 is
    probably more likely than ISO-8859-1, so it might eventually be removed
    completely.)
    
    The 'charset' member of xmlParserCtxt is now unused. The 'encoding'
    member of xmlParserInput is now unused.
    
    The 'standalone' member of xmlParserInput is renamed to 'flags'.
    
    A new parser state XML_PARSER_XML_DECL is added for the push parser.