diff --git a/src/apps/webpositive/URLInputGroup.cpp b/src/apps/webpositive/URLInputGroup.cpp index 35a6130181..57c1d8baa7 100644 --- a/src/apps/webpositive/URLInputGroup.cpp +++ b/src/apps/webpositive/URLInputGroup.cpp @@ -317,25 +317,19 @@ void URLInputGroup::URLTextView::InsertText(const char* inText, int32 inLength, int32 inOffset, const text_run_array* inRuns) { - char* buffer = NULL; - - if (strpbrk(inText, "\r\n") && inLength <= 1024) { - buffer = (char*)malloc(inLength + 1); - - if (buffer) { - strlcpy(buffer, inText, inLength + 1); - - for (int32 i = 0; i < inLength; i++) { - if (buffer[i] == '\r' || buffer[i] == '\n') - buffer[i] = ' '; - } - } + // Filter all line breaks, note that inText is not terminated. + if (inLength == 1) { + if (*inText == '\n' || *inText == '\r') + BTextView::InsertText(" ", 1, inOffset, inRuns); + else + BTextView::InsertText(inText, 1, inOffset, inRuns); + } else { + BString filteredText(inText, inLength); + filteredText.ReplaceAll('\n', ' '); + filteredText.ReplaceAll('\r', ' '); + BTextView::InsertText(filteredText.String(), inLength, inOffset, + inRuns); } - - BTextView::InsertText(buffer ? buffer : inText, inLength, inOffset, - inRuns); - - free(buffer); }