fix for cases with retrieved binary files (preventing difflib nagging around comparison)

This commit is contained in:
Miroslav Stampar 2011-05-25 20:54:30 +00:00
parent a1fd2898a0
commit 5369657cd5
2 changed files with 8 additions and 5 deletions

View File

@ -9,8 +9,6 @@ See the file 'doc/COPYING' for copying permission
import re import re
from difflib import SequenceMatcher
from lib.core.common import getFilteredPageContent from lib.core.common import getFilteredPageContent
from lib.core.common import removeDynamicContent from lib.core.common import removeDynamicContent
from lib.core.common import wasLastRequestDBMSError from lib.core.common import wasLastRequestDBMSError
@ -19,6 +17,7 @@ from lib.core.data import conf
from lib.core.data import kb from lib.core.data import kb
from lib.core.data import logger from lib.core.data import logger
from lib.core.exception import sqlmapNoneDataException from lib.core.exception import sqlmapNoneDataException
from lib.core.settings import DEFAULT_PAGE_ENCODING
from lib.core.settings import DIFF_TOLERANCE from lib.core.settings import DIFF_TOLERANCE
from lib.core.settings import MIN_RATIO from lib.core.settings import MIN_RATIO
from lib.core.settings import MAX_RATIO from lib.core.settings import MAX_RATIO
@ -70,6 +69,13 @@ def comparison(page, getRatioValue=False, pageLength=None):
if ratio > 1.: if ratio > 1.:
ratio = 1. / ratio ratio = 1. / ratio
else: else:
# Preventing "Unicode equal comparison failed to convert both arguments to Unicode"
# (e.g. if one page is PDF and the other is HTML)
if isinstance(seqMatcher.a, str) and isinstance(page, unicode):
page = page.encode(kb.pageEncoding or DEFAULT_PAGE_ENCODING)
elif isinstance(seqMatcher.a, unicode) and isinstance(page, str):
seqMatcher.a = seqMatcher.a.encode(kb.pageEncoding or DEFAULT_PAGE_ENCODING)
seqMatcher.set_seq1(getFilteredPageContent(seqMatcher.a, True) if conf.textOnly else seqMatcher.a) seqMatcher.set_seq1(getFilteredPageContent(seqMatcher.a, True) if conf.textOnly else seqMatcher.a)
seqMatcher.set_seq2(getFilteredPageContent(page, True) if conf.textOnly else page) seqMatcher.set_seq2(getFilteredPageContent(page, True) if conf.textOnly else page)
if seqMatcher.a is None or seqMatcher.b is None: if seqMatcher.a is None or seqMatcher.b is None:

View File

@ -530,9 +530,6 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
if len(finalValue) > INFERENCE_BLANK_BREAK and finalValue[-INFERENCE_BLANK_BREAK:].isspace(): if len(finalValue) > INFERENCE_BLANK_BREAK and finalValue[-INFERENCE_BLANK_BREAK:].isspace():
break break
if finalValue:
finalValue = finalValue.rstrip(INFERENCE_UNKNOWN_CHAR)
if conf.verbose in (1, 2) or showEta: if conf.verbose in (1, 2) or showEta:
dataToStdout("\n") dataToStdout("\n")