Skip to content

Commit 3ac6d2e

Browse files
committed
Merge branch 'BUG19481761' into develop
2 parents 4032144 + d454651 commit 3ac6d2e

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/mysql/connector/optionfiles.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def _parse_options(self, files):
193193
for line in op_file.readlines():
194194
if line.startswith('!includedir'):
195195
_, dir_path = line.split(None, 1)
196+
dir_path = dir_path.strip()
196197
for entry in os.listdir(dir_path):
197198
entry = os.path.join(dir_path, entry)
198199
if entry in files:
@@ -204,6 +205,7 @@ def _parse_options(self, files):
204205

205206
elif line.startswith('!include'):
206207
_, filename = line.split(None, 1)
208+
filename = filename.strip()
207209
if filename in files:
208210
raise ValueError(err_msg.format(
209211
filename, file_))
@@ -249,7 +251,6 @@ def read(self, filenames): # pylint: disable=W0221
249251
else:
250252
out_file.write(line + '\n')
251253
out_file.seek(0)
252-
self._read(out_file, filename)
253254
except IOError:
254255
continue
255256
try:

tests/test_bugs.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
to be created first.
3636
"""
3737

38+
import io
3839
import os
3940
import gc
4041
import tempfile
@@ -2833,3 +2834,36 @@ def test_unsupported_arguments(self):
28332834
exp.update(config)
28342835

28352836
self.assertEqual(exp, new_config)
2837+
2838+
2839+
class BugOra19481761(tests.MySQLConnectorTests):
2840+
"""BUG#19481761: OPTION_FILES + !INCLUDE FAILS WITH TRAILING NEWLINE
2841+
"""
2842+
def test_option_files_with_include(self):
2843+
temp_cnf_file = os.path.join(os.getcwd(), 'temp.cnf')
2844+
temp_include_file = os.path.join(os.getcwd(), 'include.cnf')
2845+
2846+
cnf_file = open(temp_cnf_file, "w+")
2847+
include_file = open(temp_include_file, "w+")
2848+
2849+
config = tests.get_mysql_config()
2850+
2851+
cnf = "[connector_python]\n"
2852+
cnf += '\n'.join(['{0} = {1}'.format(key, value)
2853+
for key, value in config.items()])
2854+
2855+
include_file.write(cnf)
2856+
cnf_file.write("!include {0}\n".format(temp_include_file))
2857+
2858+
cnf_file.close()
2859+
include_file.close()
2860+
2861+
try:
2862+
conn = mysql.connector.connect(option_files=temp_cnf_file)
2863+
except:
2864+
self.fail("Connection failed with option_files argument.")
2865+
2866+
self.assertEqual(config, read_option_files(option_files=temp_cnf_file))
2867+
2868+
os.remove(temp_cnf_file)
2869+
os.remove(temp_include_file)

0 commit comments

Comments
 (0)