Bug report #7735

QgsProject.writeEntry bugs with line endings

Added by Olivier Dalang about 11 years ago. Updated almost 10 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Project Loading/Saving
Affected QGIS version:master Regression?:No
Operating System:windows Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:16641

Description

Hi !

When saving multiline strings with writeEntry, you get the following bug (tested on windows)

text = '''a
b
c'''

QgsProject.instance().writeEntry('test','test',text)

QgsProject.instance().readEntry('test','test')[0] # this works fine : prints  PyQt4.QtCore.QString(u'a\
b\
c')

# save and reopen file

QgsProject.instance().readEntry('test','test')[0] # now, this prints  PyQt4.QtCore.QString(u'a\
\
b\
\
c')

# save and reopen file several time

QgsProject.instance().readEntry('test','test')[0] # now, this prints  PyQt4.QtCore.QString(u'a\
\
\
\
\
b\
\
\
\
\
c')

So you end up with a string having a lot of useless linebreaks... In the file, it looks like this :

        <test>
            <test type="QString">a&#xd;&#xd;&#xd;&#xd;
b&#xd;&#xd;&#xd;&#xd;
c</test>
        </test>

Related issues

Duplicates QGIS Application - Bug report #6407: Sometimes QGIS inserts extra blank lines in the project ... Closed 2012-09-24

Associated revisions

Revision 81f677d5
Added by Giuseppe Sucameli about 11 years ago

open project file using text mode (fix #7735)

Revision d62a4981
Added by Jürgen Fischer almost 10 years ago

don't write project files with native line endings on windows
(fixes #6407, fixes #7735, fixes #8267)

History

#1 Updated by Giuseppe Sucameli about 11 years ago

  • Status changed from Open to Closed

#2 Updated by Olivier Dalang over 10 years ago

  • Status changed from Closed to Reopened

Hi ! It seems the bug reappeared (or never really disappeared ?!!).

It affects the "save query" feature of the DB manager but could also affect other elements.

The problem seems to be already present on 2.0.1 (but I could almost swear it worked well some time ago, maybe for 2.0 ?)

Thanks !!

text = '''a
b
c'''

QgsProject.instance().writeEntry('test','test',text)

QgsProject.instance().readEntry('test','test')[0] # this works fine : prints  u'a\
b\
c'

# save and reopen file

QgsProject.instance().readEntry('test','test')[0] # now, this prints  u'a\
\
b\
\
c'

# save and reopen file several time

QgsProject.instance().readEntry('test','test')[0] # now, this prints  u'a\
\
\
\
\
b\
\
\
\
\
c'

#3 Updated by Giovanni Manghi over 10 years ago

  • Target version changed from Version 2.0.0 to Future Release - High Priority

#4 Updated by Jürgen Fischer almost 10 years ago

  • Category set to Project Loading/Saving

#5 Updated by Jürgen Fischer almost 10 years ago

  • Status changed from Reopened to Closed

Also available in: Atom PDF