<table><tr><td style="">flherne created this revision.<br />Restricted Application added a subscriber: kdevelop-devel.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D5707" rel="noreferrer">View Revision</a></tr></table><br /><div><strong>REVISION SUMMARY</strong><div><p>When the file being parsed is open in the editor, <tt style="background: #ebebeb; font-size: 13px;"> ParseJob::readContents()</tt> uses <tt style="background: #ebebeb; font-size: 13px;">KTextEditor::Document::text()</tt> to read the contents. At some point within KTextEditor, the line endings are normalized - even if the document uses <tt style="background: #ebebeb; font-size: 13px;">\r</tt> or <tt style="background: #ebebeb; font-size: 13px;">\r\n</tt>, the returned content is separated by <tt style="background: #ebebeb; font-size: 13px;">\n</tt> only.</p>

<p>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.</p>

<p>Several places in kdev-python assume that lines can be separated by, and end with, <tt style="background: #ebebeb; font-size: 13px;">\n</tt>. Old-style Macintosh endings (<tt style="background: #ebebeb; font-size: 13px;">\r</tt>) break this assumption, in the worst case causing a crash.</p>

<p>BUG: 378827</p>

<p>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.</p>

<p>TODO: Enforce final newline?</p></div></div><br /><div><strong>TEST PLAN</strong><div><p>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.</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R33 KDevPlatform</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D5707" rel="noreferrer">https://phabricator.kde.org/D5707</a></div></div><br /><div><strong>AFFECTED FILES</strong><div><div>language/backgroundparser/parsejob.cpp</div></div></div><br /><div><strong>To: </strong>flherne, brauch, KDevelop<br /><strong>Cc: </strong>kdevelop-devel<br /></div>