summaryrefslogtreecommitdiffstats
path: root/src/if_python.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2004-07-26 12:53:41 +0000
committerBram Moolenaar <Bram@vim.org>2004-07-26 12:53:41 +0000
commit5eb86f91992f5291b8b472d3e1be1888508777e6 (patch)
tree15dcd4c748c38e99951e79d02eb1b93f3a6d3db9 /src/if_python.c
parent89cb5e0f646970371359c70927bf3a0cdaf47f27 (diff)
updated for version 7.0012v7.0012
Diffstat (limited to 'src/if_python.c')
-rw-r--r--src/if_python.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/if_python.c b/src/if_python.c
index 21c4365203..8f4fdfd190 100644
--- a/src/if_python.c
+++ b/src/if_python.c
@@ -2731,6 +2731,7 @@ StringToLine(PyObject *obj)
char *save;
int len;
int i;
+ char *p;
if (obj == NULL || !PyString_Check(obj))
{
@@ -2741,14 +2742,22 @@ StringToLine(PyObject *obj)
str = PyString_AsString(obj);
len = PyString_Size(obj);
- /* Error checking: String must not contain newlines, as we
+ /*
+ * Error checking: String must not contain newlines, as we
* are replacing a single line, and we must replace it with
* a single line.
+ * A trailing newline is removed, so that append(f.readlines()) works.
*/
- if (memchr(str, '\n', len))
+ p = memchr(str, '\n', len);
+ if (p != NULL)
{
- PyErr_SetVim(_("string cannot contain newlines"));
- return NULL;
+ if (p == str + len - 1)
+ --len;
+ else
+ {
+ PyErr_SetVim(_("string cannot contain newlines"));
+ return NULL;
+ }
}
/* Create a copy of the string, with internal nulls replaced by