Created
March 3, 2020 01:19
-
-
Save JohannMG/97b93542e4be651bf161766f8451d92f to your computer and use it in GitHub Desktop.
Testing URL Parsing for Base64 URL Query Parameters in Node and Qt Framework using QUrl abd QUrlQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QCoreApplication> | |
#include <QUrl> | |
#include <QDebug> | |
#include <QUrlQuery> | |
#include <QPair> | |
#include <QString> | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
//input base64 Part: 440?s_bl=1&s_l=1&s_sc=313590150= | |
QUrl url = QUrl("customScheme://mainUrl?firstpart=DogsAreGood&DogsAreGood=NDQwP3NfYmw9MSZzX2w9MSZzX3NjPTMxMzU5MDE1MD0=&some=more" | |
, QUrl::ParsingMode::TolerantMode); | |
// Expect "customScheme" | |
qDebug() << "scheme" << url.scheme(); | |
// Expect entire ? without "mainUrl" | |
qDebug() << "query" << url.query(QUrl::PrettyDecoded); | |
// Pull out Quere | |
QUrlQuery query = QUrlQuery(url.query(QUrl::PrettyDecoded)); | |
// all key values as parsed by Qt | |
// Expect DogsAreGood VALUE to include trailing "=" | |
// EXPECT some to be included | |
for (QPair<QString, QString> pair : query.queryItems()){ | |
qDebug() << pair.first << ":" << pair.second ; | |
} | |
/* | |
Qt: TERMNINAL OUT | |
scheme "customscheme" | |
query "firstpart=DogsAreGood&DogsAreGood=NDQwP3NfYmw9MSZzX2w9MSZzX3NjPTMxMzU5MDE1MD0=&some=more" | |
"firstpart" : "DogsAreGood" | |
"DogsAreGood" : "NDQwP3NfYmw9MSZzX2w9MSZzX3NjPTMxMzU5MDE1MD0=" | |
"some" : "more" | |
------ | |
Matches / compares to Node.js Out | |
URL { | |
href: 'customscheme://mainUrl?firstpart=DogsAreGood&DogsAreGood=NDQwP3NfYmw9MSZzX2w9MSZzX3NjPTMxMzU5MDE1MD0=&some=more', | |
origin: 'null', | |
protocol: 'customscheme:', | |
username: '', | |
password: '', | |
host: 'mainUrl', | |
hostname: 'mainUrl', | |
port: '', | |
pathname: '', | |
search: '?firstpart=DogsAreGood&DogsAreGood=NDQwP3NfYmw9MSZzX2w9MSZzX3NjPTMxMzU5MDE1MD0=&some=more', | |
searchParams: URLSearchParams { | |
'firstpart' => 'DogsAreGood', | |
'DogsAreGood' => 'NDQwP3NfYmw9MSZzX2w9MSZzX3NjPTMxMzU5MDE1MD0=', | |
'some' => 'more' }, | |
hash: '' | |
} | |
*/ | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment