D5707: Normalize line endings when creating ParseJob from background file.
Francis Herne
noreply at phabricator.kde.org
Wed May 3 20:11:46 UTC 2017
flherne created this revision.
Restricted Application added a subscriber: kdevelop-devel.
REVISION SUMMARY
When the file being parsed is open in the editor, ` ParseJob::readContents()` uses `KTextEditor::Document::text()` to read the contents. At some point within KTextEditor, the line endings are normalized - even if the document uses `\r` or `\r\n`, the returned content is separated by `\n` only.
Otherwise, the contents are read directly from the file. Until this patch, the line endings aren't normalized in this case; the ParseJob contents differ depending on whether the file is open in the editor.
Several places in kdev-python assume that lines can be separated by, and end with, `\n`. Old-style Macintosh endings (`\r`) break this assumption, in the worst case causing a crash.
BUG: 378827
Using a regex in each instance would be a pain, and one code path normalizes line endings already, so I think the best option is to do so for background files also.
TODO: Enforce final newline?
TEST PLAN
Tested loading files with each of the three line-ending styles. ParseJob content is now the same regardless of whether the file is opened for editing.
REPOSITORY
R33 KDevPlatform
REVISION DETAIL
https://phabricator.kde.org/D5707
AFFECTED FILES
language/backgroundparser/parsejob.cpp
To: flherne, brauch, #kdevelop
Cc: kdevelop-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20170503/e84d6a68/attachment.html>
More information about the KDevelop-devel
mailing list