diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2014-08-14 19:45:53 +0200 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2014-08-14 19:45:53 +0200 |
commit | 2aee419ce0ba8f0d852235e63f6e8885e7244bcf (patch) | |
tree | 786a1e96739868bd991853dcf5de6306434a5365 | |
parent | 2d53ecf97d42642a6684e49b61d981103d745a42 (diff) |
improve lang and xml:lang attribute parsing
-rw-r--r-- | src/html.cc | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/html.cc b/src/html.cc index ff2eb0d1..fa1cf67d 100644 --- a/src/html.cc +++ b/src/html.cc @@ -3781,6 +3781,7 @@ static void Html_test_section(DilloHtml *html, int new_idx, int IsCloseTag) static void Html_parse_common_attrs(DilloHtml *html, char *tag, int tagsize) { const char *attrbuf; + char lang[3]; if (tagsize >= 8 && /* length of "<t id=i>" */ (attrbuf = a_Html_get_attr(html, tag, tagsize, "id"))) { @@ -3806,24 +3807,25 @@ static void Html_parse_common_attrs(DilloHtml *html, char *tag, int tagsize) html->styleEngine->setStyle (attrbuf); } - /* handle "xml:lang" and "lang" attributes */ - int hasXmlLang = 0; + /* handle "xml:lang" and "lang" attributes + * We use only the first two chars of the value to deal with + * extended language tags (see http://www.rfc-editor.org/rfc/bcp/bcp47.txt) + */ + memset(lang, 0, sizeof(lang)); if (tagsize >= 14) { /* length of "<t xml:lang=i>" */ attrbuf = a_Html_get_attr(html, tag, tagsize, "xml:lang"); - if (attrbuf) { - html->styleEngine->setNonCssHint(PROPERTY_X_LANG, CSS_TYPE_STRING, - attrbuf); - hasXmlLang = 1; - } + if (attrbuf) + strncpy(lang, attrbuf, 2); } - if (!hasXmlLang && tagsize >= 10) { /* 'xml:lang' prevails over 'lang' */ + if (!lang[0] && tagsize >= 10) { /* 'xml:lang' prevails over 'lang' */ /* length of "<t lang=i>" */ attrbuf = a_Html_get_attr(html, tag, tagsize, "lang"); if (attrbuf) - html->styleEngine->setNonCssHint(PROPERTY_X_LANG, CSS_TYPE_STRING, - attrbuf); + strncpy(lang, attrbuf, 2); } + if (lang[0]) + html->styleEngine->setNonCssHint(PROPERTY_X_LANG, CSS_TYPE_STRING, lang); } /* |