Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape quotes in strings sent from SCIDE to lang #3277

Merged
merged 3 commits into from
Jan 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions editors/sc-ide/widgets/help_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,26 @@ void HelpBrowser::closeDocument()
MainWindow::instance()->helpBrowserDocklet()->close();
}

/// Escapes double quotes; used for strings sent to interpreter.
static inline QString escapeDoubleQuotes( const QString & s )
{
return QString{s}.replace('\"', "\\\"");
}

void HelpBrowser::gotoHelpFor( const QString & symbol )
{
QString code = QStringLiteral("HelpBrowser.openHelpFor(\"%1\")").arg(symbol);
QString escaped = escapeDoubleQuotes(symbol);
QString code = QStringLiteral("HelpBrowser.openHelpFor(\"%1\")").arg(escaped);
sendRequest(code);
}

void HelpBrowser::gotoHelpForMethod( const QString & className, const QString & methodName )
{
QString code = QStringLiteral("HelpBrowser.openHelpForMethod( %1.findMethod(\\%2) )").arg(className, methodName);
QString escapedClass = escapeDoubleQuotes(className);
QString escapedMethod = escapeDoubleQuotes(methodName);

QString code = QStringLiteral("HelpBrowser.openHelpForMethod( %1.findMethod(\\%2) )")
.arg(escapedClass, escapedMethod);
sendRequest(code);
}

Expand All @@ -199,7 +210,7 @@ void HelpBrowser::onLinkClicked( const QUrl & url )
static const QStringList nonHelpFileExtensions = QStringList() << ".sc" << ".scd" << ".schelp" << ".txt" << ".rtf";
static const QString fileScheme("file");

QString urlString = url.toString();
QString urlString = escapeDoubleQuotes(url.toString());

foreach ( const QString & extension, nonHelpFileExtensions ) {
if (urlString.endsWith( extension )) {
Expand Down
6 changes: 3 additions & 3 deletions editors/sc-ide/widgets/lookup_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,10 @@ void ReferencesDialog::performQuery()

if (queryString.isEmpty()) {
setModel(NULL);
return;
} else {
queryString.replace('\"', "\\\"");
mRequest->sendRequest(queryString);
}

mRequest->sendRequest(queryString);
}

void ReferencesDialog::requestCancelled()
Expand Down