PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 1032 - unicode(QRegExp()) may raise an UnicodeDecodeError
: unicode(QRegExp()) may raise an UnicodeDecodeError
Status: RESOLVED WORKSFORME
Product: PySide
Classification: Unclassified
Component: QtCore
: HEAD
: PC Linux
: P3 normal
Assigned To: Hugo Parente Lima
:
:
:
  Show dependency treegraph
 
Reported: 2011-10-25 00:58 EEST by Hereldar
Modified: 2011-11-03 18:26 EET (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hereldar 2011-10-25 00:58:53 EEST
Steps to Reproduce:
-------------------

    from PySide.QtCore import QRegExp

    re = QRegExp('H(ä|ae?)ndel')
    re
    rep(re)
    str(re)
    unicode(re)

    re = QRegExp(u'H(ä|ae?)ndel')
    re
    rep(re)
    str(re)
    unicode(re)

Actual Results:
---------------

    PySide.QtCore.QRegExp('H(�|ae?)ndel', 1, 0)
    "PySide.QtCore.QRegExp('H(\xe4|ae?)ndel', 1, 0)"
    "PySide.QtCore.QRegExp('H(\xe4|ae?)ndel', 1, 0)"
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 25:
ordinal not in range(128)

    PySide.QtCore.QRegExp('H(?|ae?)ndel', 1, 0)
    "PySide.QtCore.QRegExp('H(?|ae?)ndel', 1, 0)"
    "PySide.QtCore.QRegExp('H(?|ae?)ndel', 1, 0)"
    u"PySide.QtCore.QRegExp('H(?|ae?)ndel', 1, 0)"

Expected Results:
-----------------

    PySide.QtCore.QRegExp('H(\xe4|ae?)ndel', 1, 0)
    "PySide.QtCore.QRegExp('H(\xe4|ae?)ndel', 1, 0)"
    "PySide.QtCore.QRegExp('H(\xe4|ae?)ndel', 1, 0)"
    u"PySide.QtCore.QRegExp('H(\xe4|ae?)ndel', 1, 0)"

    PySide.QtCore.QRegExp('H(\xe4|ae?)ndel', 1, 0)
    "PySide.QtCore.QRegExp('H(\xe4|ae?)ndel', 1, 0)"
    "PySide.QtCore.QRegExp('H(\xe4|ae?)ndel', 1, 0)"
    u"PySide.QtCore.QRegExp('H(\xe4|ae?)ndel', 1, 0)"

Platform:
---------

    Distribution: Kubuntu 11.10
    KDE S.C.:     4.7.2
    Qt:           4.7.4
    PySide:       1.0.7
Comment 1 Hugo Parente Lima 2011-11-01 21:44:55 EET
Hi,

Your code works for me. What's encoding are you using to save your source code?
If you are using UTF-8 be sure to add the header:

# -*- coding: utf-8 -*-

on top of your source code.

Another issue, if you are using Python2x and your string contains unicode
characters the string must be a unicode string, so "re =
QRegExp('H(ä|ae?)ndel')" is invalid, the correct is "re =
QRegExp(u'H(ä|ae?)ndel')"
Comment 2 Hereldar 2011-11-03 18:26:40 EET
I include that header in all my scripts. However, I did this test directly on
the console.

About the second issue, I knew what you say, but when I tested it no errors are
raised and I included it in the report.