Revision 3273

View differences:

libsylph/html.c
191 191
					 gchar		*buf,
192 192
					 gint		 len);
193 193

  
194
static gchar *html_unescape_str		(HTMLParser	*parser,
195
					 const gchar	*str);
194 196

  
197

  
195 198
HTMLParser *html_parser_new(FILE *fp, CodeConverter *conv)
196 199
{
197 200
	HTMLParser *parser;
......
553 556

  
554 557
			if (attr && !strcmp(attr->name, "href")) {
555 558
				g_free(parser->href);
556
				parser->href = g_strdup(attr->value);
559
				parser->href = html_unescape_str(parser, attr->value);
557 560
				parser->state = HTML_HREF;
558 561
				break;
559 562
			}
......
719 722
	g_strstrip(buf);
720 723
	parser->bufp = p + 1;
721 724
}
725

  
726
static gchar *html_unescape_str(HTMLParser *parser, const gchar *str)
727
{
728
	const gchar *p = str;
729
	gchar symbol_name[9];
730
	gint n;
731
	const gchar *val;
732
	gchar *unescape_str;
733
	gchar *up;
734

  
735
	if (!str)
736
		return NULL;
737

  
738
	up = unescape_str = g_malloc(strlen(str) + 1);
739

  
740
	while (*p != '\0') {
741
		switch (*p) {
742
		case '&':
743
			for (n = 0; p[n] != '\0' && p[n] != ';'; n++)
744
				;
745
			if (n > 7 || p[n] != ';') {
746
				*up++ = *p++;
747
				break;
748
			}
749
			strncpy2(symbol_name, p, n + 2);
750
			p += n + 1;
751

  
752
			if ((val = g_hash_table_lookup(parser->symbol_table, symbol_name)) != NULL) {
753
				gint len = strlen(val);
754
				if (len <= n + 1) {
755
					strcpy(up, val);
756
					up += len;
757
				} else {
758
					strcpy(up, symbol_name);
759
					up += n + 1;
760
				}
761
			} else if (symbol_name[1] == '#' && g_ascii_isdigit(symbol_name[2])) {
762
				gint ch;
763

  
764
				ch = atoi(symbol_name + 2);
765
				if (ch < 128 && g_ascii_isprint(ch)) {
766
					*up++ = ch;
767
				} else {
768
					/* ISO 10646 to UTF-8 */
769
					gchar buf[6];
770
					gint len;
771

  
772
					len = g_unichar_to_utf8((gunichar)ch, buf);
773
					if (len > 0 && len <= n + 1) {
774
						memcpy(up, buf, len);
775
						up += len;
776
					} else {
777
						strcpy(up, symbol_name);
778
						up += n + 1;
779
					}
780
				}
781
			}
782

  
783
			break;
784
		default:
785
			*up++ = *p++;
786
		}
787
	}
788

  
789
	*up = '\0';
790
	return unescape_str;
791
}
ChangeLog
1
2013-08-26
2

  
3
	* libsylph/html.c: properly unescape special characters in links
4
	  (#120).
5

  
1 6
2013-08-16
2 7

  
3 8
	* libsylph/imap.c: imap_status(): fixed the parse failure of STATUS response

Also available in: Unified diff