Bug 431706 - DefaultValueGetter for Url type uses fromUserInput which doesn't handle "qrc:/"
Summary: DefaultValueGetter for Url type uses fromUserInput which doesn't handle "qrc:/"
Status: REPORTED
Alias: None
Product: frameworks-kconfig
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.68.0
Platform: Other All
: NOR normal
Target Milestone: ---
Assignee: Matthew Dawson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-16 19:13 UTC by Dawid Wróbel
Modified: 2021-01-16 20:57 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dawid Wróbel 2021-01-16 19:13:29 UTC
SUMMARY

A default value helper for a kcfg entry of a "Url" type that has a default value pointing to "qrc:/" Qt resource (which itself is a valid Url) will return a QUrl object initialized improperly with a malformed "file:qrc:/" value. 

This is due to the fact that the helper uses QUrl::fromUserInput() to parse the provided value, which in turn does not handle the "qrc:/" Urls, and Qt refuses to make it to. Relevant discussion about fromLocalFile() that behaves identically here: 
https://bugreports.qt.io/browse/QTBUG-44165

The proposed solution is to make the helper detect the qrc:/ substring and initialize QUrl object directly: 

    if (urlString.startsWith(QStringLiteral("qrc:/"))) {
      return QUrl(urlString));
    }
    else {
      return QUrl::fromUserInput(urlString)


STEPS TO REPRODUCE
1. Add a kcfg entry:
    <entry name="SomeConfigSwitch" type="Url">
      <default>qrc:/someConfigValue</default>
    </entry>
2. Add "DefaultValueGetters=true" to .kcfgc file
3. auto defaultConfigUrlValue = PluginSettings::defaultSomeConfigSwitchValue().url()

OBSERVED RESULT
Notice that defaultConfigUrlValue is "file:qrc:/someConfigValue"


EXPECTED RESULT
defaultConfigUrlValue should be "qrc:/someConfigValue"

SOFTWARE/OS VERSIONS
Linux: Ubuntu 20.04.1 LTS
KDE Frameworks Version: 5.68
Qt Version: 5.12
Comment 1 Dawid Wróbel 2021-01-16 20:57:41 UTC
Actually, I just realized that the "SomeConfigSwitch" (using the same example) is also initialized improperly in the same fashion, so this doesn't apply to default value helpers only.