Bug 431706

Summary: DefaultValueGetter for Url type uses fromUserInput which doesn't handle "qrc:/"
Product: [Frameworks and Libraries] frameworks-kconfig Reporter: Dawid Wróbel <me>
Component: generalAssignee: Matthew Dawson <matthew>
Status: REPORTED ---    
Severity: normal CC: kdelibs-bugs-null
Priority: NOR    
Version First Reported In: 5.68.0   
Target Milestone: ---   
Platform: Other   
OS: All   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

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.