mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-29 10:34:42 +00:00
Properly detect too-long Unicode hostnames.
This commit is contained in:
parent
9871f9b071
commit
9956f3712e
3 changed files with 52 additions and 1 deletions
|
|
@ -1,8 +1,10 @@
|
|||
7.3 "" (released xx.xx.2011)
|
||||
|
||||
Fixes:
|
||||
- configuration: properly detect home directory on OS X systems.
|
||||
- configuration: Properly detect home directory on OS X systems.
|
||||
Closes: SF bug #3423110
|
||||
- checking: Proper error reporting for too-long unicode hostnames.
|
||||
Closes: SF bug #3438553
|
||||
|
||||
|
||||
7.2 "Driver" (released 20.10.2011)
|
||||
|
|
|
|||
10
linkcheck/cache/addrinfo.py
vendored
10
linkcheck/cache/addrinfo.py
vendored
|
|
@ -19,6 +19,7 @@ Cache for DNS lookups.
|
|||
"""
|
||||
import socket
|
||||
import sys
|
||||
from .. import LinkCheckerError
|
||||
from ..lock import get_lock
|
||||
from ..containers import LFUCache
|
||||
from ..decorators import synchronized
|
||||
|
|
@ -35,10 +36,19 @@ def getaddrinfo (host, port):
|
|||
if key in addrinfos:
|
||||
value = addrinfos[key]
|
||||
else:
|
||||
# check if it's an ascii host
|
||||
if isinstance(host, unicode):
|
||||
try:
|
||||
host = host.encode('ascii')
|
||||
except UnicodeEncodeError:
|
||||
pass
|
||||
try:
|
||||
value = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)
|
||||
except socket.error:
|
||||
value = sys.exc_info()[1]
|
||||
except UnicodeError, msg:
|
||||
args = dict(host=host, msg=str(msg))
|
||||
value = LinkCheckerError(_("could not parse host %(host)r: %(msg)s") % args)
|
||||
addrinfos[key] = value
|
||||
if isinstance(value, Exception):
|
||||
raise value
|
||||
|
|
|
|||
39
tests/cache/test_addrinfo.py
vendored
Normal file
39
tests/cache/test_addrinfo.py
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: iso-8859-1 -*-
|
||||
# Copyright (C) 2011 Bastian Kleineidam
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
"""
|
||||
Test address info caching.
|
||||
"""
|
||||
import unittest
|
||||
import socket
|
||||
from linkcheck import LinkCheckerError
|
||||
from linkcheck.cache.addrinfo import getaddrinfo
|
||||
|
||||
class TestAddrinfoCache (unittest.TestCase):
|
||||
"""Test address info caching."""
|
||||
|
||||
def test_addrinfo_cache1 (self):
|
||||
# pure ascii hostname with >63 chars
|
||||
host = u"a"*64
|
||||
port = 80
|
||||
# must not raise UnicodeEncodeError
|
||||
self.assertRaises(socket.error, getaddrinfo, host, port)
|
||||
|
||||
def test_addrinfo_cache2 (self):
|
||||
# non-ascii hostname with >63 chars
|
||||
host = u"ä"*64
|
||||
port = 80
|
||||
self.assertRaises(LinkCheckerError, getaddrinfo, host, port)
|
||||
Loading…
Reference in a new issue