summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjvoisin2018-01-03 14:23:29 +0100
committerjvoisin2018-01-03 14:24:05 +0100
commitbc55f1ccd1c995f7ab502323c96f5a44352a5a80 (patch)
tree7cc46d06068e3d05e8e7ef25397c70af56ce7c50 /src
parentba4cf621c33de08680d851b549eaaa009d5785f4 (diff)
Handle correctly configuration files with Windows EOL
Thanks to @fr33tux for the bug report ♥
Diffstat (limited to 'src')
-rw-r--r--src/sp_config.c6
-rw-r--r--src/tests/config/windows_eol.ini2
-rw-r--r--src/tests/windows_eol.phpt10
3 files changed, 17 insertions, 1 deletions
diff --git a/src/sp_config.c b/src/sp_config.c
index aeadd9d..4d95062 100644
--- a/src/sp_config.c
+++ b/src/sp_config.c
@@ -175,7 +175,11 @@ int sp_parse_config(const char *conf_file) {
175 while (getline(&lineptr, &n, fd) > 0) { 175 while (getline(&lineptr, &n, fd) > 0) {
176 /* We trash the terminal `\n`. This simplify the display of logs. */ 176 /* We trash the terminal `\n`. This simplify the display of logs. */
177 if (lineptr[strlen(lineptr) - 1] == '\n') { 177 if (lineptr[strlen(lineptr) - 1] == '\n') {
178 lineptr[strlen(lineptr) - 1] = '\0'; 178 if (lineptr[strlen(lineptr) - 2] == '\r') {
179 lineptr[strlen(lineptr) - 2] = '\0';
180 } else {
181 lineptr[strlen(lineptr) - 1] = '\0';
182 }
179 } 183 }
180 if (parse_line(lineptr) == -1) { 184 if (parse_line(lineptr) == -1) {
181 fclose(fd); 185 fclose(fd);
diff --git a/src/tests/config/windows_eol.ini b/src/tests/config/windows_eol.ini
new file mode 100644
index 0000000..eea230c
--- /dev/null
+++ b/src/tests/config/windows_eol.ini
@@ -0,0 +1,2 @@
1sp.disable_function.function("assert").filename("/tst.php").hash("0df5e049bf954da7054273bd66a3c63e7cbc22fea31bb448c6229f92f04af2b3").allow();
2
diff --git a/src/tests/windows_eol.phpt b/src/tests/windows_eol.phpt
new file mode 100644
index 0000000..0e81274
--- /dev/null
+++ b/src/tests/windows_eol.phpt
@@ -0,0 +1,10 @@
1--TEST--
2Windows EOL in configuration file
3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
5--INI--
6sp.configuration_file={PWD}/config/windows_eol.ini
7--FILE--
8<?php echo "1\n"; ?>
9--EXPECT--
101