From db95fce77e6f967410c7f4225fe9de5241440154 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Sun, 10 Jun 2012 14:02:01 +0200 Subject: [PATCH] Ignore PHP processing instructions in local files. --- doc/changelog.txt | 6 ++++++ linkcheck/checker/__init__.py | 11 ++++++++--- linkcheck/checker/ignoreurl.py | 28 ++++++++++++++++++++++++++++ linkcheck/checker/urlbase.py | 2 +- linkcheck/fileutil.py | 2 +- tests/checker/data/file.php | 3 +++ tests/checker/data/file.php.result | 14 ++++++++++++++ 7 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 linkcheck/checker/ignoreurl.py diff --git a/doc/changelog.txt b/doc/changelog.txt index 05574ca9..214e00ee 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -5,6 +5,12 @@ Fixes: Closes: SF bug #3528450 - checking: Fix writing temporary files. +Changes: +- checking: Ignore URLs from local PHP files with execution + directives of the form "". + Prevents false errors when checking local PHP files. + Closes: SF bug #3532763 + Features: - installation: Support RPM building with cx_Freeze. - installation: Added .desktop files for POSIX systems. diff --git a/linkcheck/checker/__init__.py b/linkcheck/checker/__init__.py index e56bdd74..8352b867 100644 --- a/linkcheck/checker/__init__.py +++ b/linkcheck/checker/__init__.py @@ -50,7 +50,7 @@ def absolute_url (base_url, base_ref, parent_url): def get_url_from (base_url, recursion_level, aggregate, parent_url=None, base_ref=None, line=0, column=0, - name=u""): + name=u"", parent_content_type=None): """ Get url data from given base data. @@ -86,7 +86,12 @@ def get_url_from (base_url, recursion_level, aggregate, if not (url or name): # use filename as base url, with slash as path seperator name = base_url.replace("\\", "/") - klass = get_urlclass_from(url) + if parent_content_type == 'application/x-httpd-php' and \ + 'Bla + +PHP 1 +PHP 2 diff --git a/tests/checker/data/file.php.result b/tests/checker/data/file.php.result index 9f28238e..f033f56e 100644 --- a/tests/checker/data/file.php.result +++ b/tests/checker/data/file.php.result @@ -9,3 +9,17 @@ cache key file://%(curdir)s/%(datadir)s/anchor.html real url file://%(curdir)s/%(datadir)s/anchor.html name Bla valid + +url test_ +cache key file://%(curdir)s/%(datadir)s/test_%%3C?%%20echo%%20%%24module%%20?%%3E +real url file://%(curdir)s/%(datadir)s/test_%%3C?%%20echo%%20%%24module%%20?%%3E +name PHP 1 +warning File URL ignored. +valid + +url test_ +cache key file://%(curdir)s/%(datadir)s/test_%%3C?php%%20echo%%20%%24module%%20?%%3E +real url file://%(curdir)s/%(datadir)s/test_%%3C?php%%20echo%%20%%24module%%20?%%3E +name PHP 2 +warning File URL ignored. +valid