Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
fix: replaced null character(\x00) to fix escaping error while writin… (
Browse files Browse the repository at this point in the history
#87)

* fix: replaced null character(\x00) to fix escaping error while writing to csv.

* chore: Added test.

---------

Co-authored-by: Hassan Javeed <[email protected]>
  • Loading branch information
HassanJaveed84 and HassanJaveed84 authored Jul 13, 2023
1 parent a1d5e97 commit 87ad53d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion exporter/mysql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ def _write_results_to_tsv(self, cursor, output_file):

def _normalize_value(self, value):
if value is None: value='NULL'
return str(value).replace('\\', '\\\\').replace('\r', '\\r').replace('\t','\\t').replace('\n', '\\n')
return str(value).replace('\\', '\\\\').replace('\r', '\\r').replace('\t','\\t').replace('\n', '\\n').replace('\x00', '')
13 changes: 13 additions & 0 deletions exporter/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,16 @@ def test_course_task_get_filename_on_similar_names():
kwargs['name'] = ('a' * 999) + 'b'
file_name3 = os.path.basename(TestCourseTask.get_filename(**kwargs))
assert len(set([file_name1, file_name2, file_name3])) == 3

def test_normalize_value_with_null_character():
"""
Test that a null character is removed from a string.
"""
mysql_task = tasks.MysqlDumpQueryToTSV(
host='localhost',
username='root',
password='password',
database='test',
destination_filename='test.tsv',
)
assert mysql_task._normalize_value('abc\x00') == 'abc'

0 comments on commit 87ad53d

Please sign in to comment.