From 480e52fddf28fad591f3214ee28c2d2af8842ce1 Mon Sep 17 00:00:00 2001 From: Michael Schuller Date: Fri, 7 Mar 2014 18:01:41 +0000 Subject: Fix SerializerUnicode to split unquoted newlines This provides a fix to issue #131. The `split_unquoted_newlines()` function added to the utils module handles the splitting of the string by performing a simple iteration of the string passed in and splitting on unquoted CR, LF, or CR+LFs as they are found. --- tests/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests/utils.py') diff --git a/tests/utils.py b/tests/utils.py index e2c01a3..9eb46bf 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -8,6 +8,8 @@ import os import unittest from StringIO import StringIO +import sqlparse.utils + NL = '\n' DIR_PATH = os.path.abspath(os.path.dirname(__file__)) PARENT_DIR = os.path.dirname(DIR_PATH) @@ -31,7 +33,12 @@ class TestCaseBase(unittest.TestCase): if first != second: sfirst = unicode(first) ssecond = unicode(second) - diff = difflib.ndiff(sfirst.splitlines(), ssecond.splitlines()) + # Using the built-in .splitlines() method here will cause incorrect + # results when splitting statements that have quoted CR/CR+LF + # characters. + sfirst = sqlparse.utils.split_unquoted_newlines(sfirst) + ssecond = sqlparse.utils.split_unquoted_newlines(ssecond) + diff = difflib.ndiff(sfirst, ssecond) fp = StringIO() fp.write(NL) fp.write(NL.join(diff)) -- cgit v1.2.1