Mercurial > pidgin.yaz
comparison src/util.c @ 10461:e94802fe3eaf
[gaim-migrate @ 11733]
I think this is a better fix for bug 1013543 (because it also fixes 1086228)
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Fri, 31 Dec 2004 14:02:10 +0000 |
parents | bbe937302b47 |
children | 4f67724c207c |
comparison
equal
deleted
inserted
replaced
10460:83cfcb52d93b | 10461:e94802fe3eaf |
---|---|
1368 str2[j] = '\0'; | 1368 str2[j] = '\0'; |
1369 | 1369 |
1370 return str2; | 1370 return str2; |
1371 } | 1371 } |
1372 | 1372 |
1373 static gint | 1373 static gboolean |
1374 badchar(char c) | 1374 badchar(char c) |
1375 { | 1375 { |
1376 switch (c) { | 1376 switch (c) { |
1377 case ' ': | 1377 case ' ': |
1378 case ',': | 1378 case ',': |
1380 case '\n': | 1380 case '\n': |
1381 case '<': | 1381 case '<': |
1382 case '>': | 1382 case '>': |
1383 case '"': | 1383 case '"': |
1384 case '\'': | 1384 case '\'': |
1385 return 1; | 1385 return TRUE; |
1386 default: | 1386 default: |
1387 return 0; | 1387 return FALSE; |
1388 } | 1388 } |
1389 } | |
1390 | |
1391 static gboolean | |
1392 badentity(const char *c) | |
1393 { | |
1394 if (!g_ascii_strncasecmp(c, "<", 4) || | |
1395 !g_ascii_strncasecmp(c, ">", 4) || | |
1396 !g_ascii_strncasecmp(c, """, 6)) { | |
1397 return TRUE; | |
1398 } | |
1399 return FALSE; | |
1389 } | 1400 } |
1390 | 1401 |
1391 char * | 1402 char * |
1392 gaim_markup_linkify(const char *text) | 1403 gaim_markup_linkify(const char *text) |
1393 { | 1404 { |
1434 } | 1445 } |
1435 } else if ((*c=='h') && (!g_ascii_strncasecmp(c, "http://", 7) || | 1446 } else if ((*c=='h') && (!g_ascii_strncasecmp(c, "http://", 7) || |
1436 (!g_ascii_strncasecmp(c, "https://", 8)))) { | 1447 (!g_ascii_strncasecmp(c, "https://", 8)))) { |
1437 t = c; | 1448 t = c; |
1438 while (1) { | 1449 while (1) { |
1439 if (badchar(*t)) { | 1450 if (badchar(*t) || badentity(t)) { |
1440 | 1451 |
1441 if (*(t) == ',' && (*(t + 1) != ' ')) { | 1452 if (*(t) == ',' && (*(t + 1) != ' ')) { |
1442 t++; | 1453 t++; |
1443 continue; | 1454 continue; |
1444 } | 1455 } |
1446 if (*(t - 1) == '.') | 1457 if (*(t - 1) == '.') |
1447 t--; | 1458 t--; |
1448 if ((*(t - 1) == ')' && (inside_paren > 0))) { | 1459 if ((*(t - 1) == ')' && (inside_paren > 0))) { |
1449 t--; | 1460 t--; |
1450 } | 1461 } |
1451 if (!g_ascii_strncasecmp(t - 6, """, 6)) | 1462 |
1452 t -= 6; | |
1453 strncpy(url_buf, c, t - c); | 1463 strncpy(url_buf, c, t - c); |
1454 url_buf[t - c] = 0; | 1464 url_buf[t - c] = 0; |
1455 tmpurlbuf = gaim_unescape_html(url_buf); | 1465 tmpurlbuf = gaim_unescape_html(url_buf); |
1456 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>", | 1466 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>", |
1457 tmpurlbuf, url_buf); | 1467 tmpurlbuf, url_buf); |
1466 } | 1476 } |
1467 } else if (!g_ascii_strncasecmp(c, "www.", 4)) { | 1477 } else if (!g_ascii_strncasecmp(c, "www.", 4)) { |
1468 if (c[4] != '.') { | 1478 if (c[4] != '.') { |
1469 t = c; | 1479 t = c; |
1470 while (1) { | 1480 while (1) { |
1471 if (badchar(*t)) { | 1481 if (badchar(*t) || badentity(t)) { |
1472 if (t - c == 4) { | 1482 if (t - c == 4) { |
1473 break; | 1483 break; |
1474 } | 1484 } |
1475 | 1485 |
1476 if (*(t) == ',' && (*(t + 1) != ' ')) { | 1486 if (*(t) == ',' && (*(t + 1) != ' ')) { |
1499 } | 1509 } |
1500 } | 1510 } |
1501 } else if (!g_ascii_strncasecmp(c, "ftp://", 6)) { | 1511 } else if (!g_ascii_strncasecmp(c, "ftp://", 6)) { |
1502 t = c; | 1512 t = c; |
1503 while (1) { | 1513 while (1) { |
1504 if (badchar(*t)) { | 1514 if (badchar(*t) || badentity(t)) { |
1505 if (*(t - 1) == '.') | 1515 if (*(t - 1) == '.') |
1506 t--; | 1516 t--; |
1507 if ((*(t - 1) == ')' && (inside_paren > 0))) { | 1517 if ((*(t - 1) == ')' && (inside_paren > 0))) { |
1508 t--; | 1518 t--; |
1509 } | 1519 } |
1523 } | 1533 } |
1524 } else if (!g_ascii_strncasecmp(c, "ftp.", 4)) { | 1534 } else if (!g_ascii_strncasecmp(c, "ftp.", 4)) { |
1525 if (c[4] != '.') { | 1535 if (c[4] != '.') { |
1526 t = c; | 1536 t = c; |
1527 while (1) { | 1537 while (1) { |
1528 if (badchar(*t)) { | 1538 if (badchar(*t) || badentity(t)) { |
1529 if (t - c == 4) { | 1539 if (t - c == 4) { |
1530 break; | 1540 break; |
1531 } | 1541 } |
1532 if (*(t - 1) == '.') | 1542 if (*(t - 1) == '.') |
1533 t--; | 1543 t--; |
1550 } | 1560 } |
1551 } | 1561 } |
1552 } else if (!g_ascii_strncasecmp(c, "mailto:", 7)) { | 1562 } else if (!g_ascii_strncasecmp(c, "mailto:", 7)) { |
1553 t = c; | 1563 t = c; |
1554 while (1) { | 1564 while (1) { |
1555 if (badchar(*t)) { | 1565 if (badchar(*t) || badentity(t)) { |
1556 if (*(t - 1) == '.') | 1566 if (*(t - 1) == '.') |
1557 t--; | 1567 t--; |
1558 strncpy(url_buf, c, t - c); | 1568 strncpy(url_buf, c, t - c); |
1559 url_buf[t - c] = 0; | 1569 url_buf[t - c] = 0; |
1560 tmpurlbuf = gaim_unescape_html(url_buf); | 1570 tmpurlbuf = gaim_unescape_html(url_buf); |
1604 t = g_utf8_find_next_char(c, NULL); | 1614 t = g_utf8_find_next_char(c, NULL); |
1605 | 1615 |
1606 while (flag) { | 1616 while (flag) { |
1607 /* iterate forwards grabbing the domain part of an email address */ | 1617 /* iterate forwards grabbing the domain part of an email address */ |
1608 g = g_utf8_get_char(t); | 1618 g = g_utf8_get_char(t); |
1609 if (badchar(*t) || (g >= 127) || (*t == ')') || | 1619 if (badchar(*t) || (g >= 127) || (*t == ')') || badentity(t)) { |
1610 ((*t == '&') && !g_ascii_strncasecmp(t, ">", 4))) { | |
1611 char *d; | 1620 char *d; |
1612 | 1621 |
1613 strcpy(url_buf, gurl_buf->str); | 1622 strcpy(url_buf, gurl_buf->str); |
1614 | 1623 |
1615 /* strip off trailing periods */ | 1624 /* strip off trailing periods */ |