diff options
author | ianb <devnull@localhost> | 2008-11-24 02:49:49 +0000 |
---|---|---|
committer | ianb <devnull@localhost> | 2008-11-24 02:49:49 +0000 |
commit | d4e9e8413f2253280465e56f1e6ebdac88888885 (patch) | |
tree | 43ad2db277ba42192d21beb188595f4423174edf | |
parent | ea5f8d39d42f8788fc2a090f7c417657dc9fa9f6 (diff) | |
download | webtest-d4e9e8413f2253280465e56f1e6ebdac88888885.tar.gz |
try to skip links in <script> tags
-rw-r--r-- | docs/index.txt | 3 | ||||
-rw-r--r-- | webtest/__init__.py | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/docs/index.txt b/docs/index.txt index 000384f..94c4b6a 100644 --- a/docs/index.txt +++ b/docs/index.txt @@ -381,6 +381,9 @@ svn trunk which sets the ``Content-Type`` of the request. This is more convenient when testing REST APIs. +* Skip links in ``<script>...</script>`` tags (since that's not real + markup). + 1.0.2 ----- diff --git a/webtest/__init__.py b/webtest/__init__.py index 7496115..d02a3bd 100644 --- a/webtest/__init__.py +++ b/webtest/__init__.py @@ -550,6 +550,10 @@ class TestResponse(Response): _tag_re = re.compile(r'<%s\s+(.*?)>(.*?)</%s>' % (tag, tag), re.I+re.S) + _script_re = re.compile(r'<script.*?>.*?</script>', re.I|re.S) + bad_spans = [] + for match in _script_re.finditer(self.body): + bad_spans.append((match.start(), match.end())) def printlog(s): if verbose: @@ -558,6 +562,14 @@ class TestResponse(Response): found_links = [] total_links = 0 for match in _tag_re.finditer(self.body): + found_bad = False + for bad_start, bad_end in bad_spans: + if (match.start() > bad_start + and match.end() < bad_end): + found_bad = True + break + if found_bad: + continue el_html = match.group(0) el_attr = match.group(1) el_content = match.group(2) |