Skip to content

Commit

Permalink
Fix importing regexes with slashes in scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Aug 23, 2023
1 parent d92c62c commit afaf92c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/scriptable/scriptable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,15 @@ struct ScriptValueFactory<QRegularExpression> {
static QRegularExpression fromScriptValue(const QJSValue &value, const Scriptable *)
{
if (value.isRegExp()) {
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
const auto variant = value.toVariant();
return variant.toRegularExpression();
#else
const QString pattern = toString(value.property("source"));
return pattern == QStringLiteral("(?:)")
? QRegularExpression()
: QRegularExpression(pattern);
#endif
}

if (value.isVariant()) {
Expand Down
6 changes: 3 additions & 3 deletions src/tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,7 @@ void Tests::commandsAddCommandsRegExp()
{
const QString commands =
"[Command]\n"
"Match=x\n";
"Match=^(https?|ftps?)://\\\\$\n";

// Ensure there is a basic RegExp support.
RUN("/test/", "/test/\n");
Expand All @@ -1720,15 +1720,15 @@ void Tests::commandsAddCommandsRegExp()
RUN("eval" << "exportCommands(importCommands(arguments[1]))" << "--" << commands, commands);
RUN("eval" << "Object.prototype.toString.call(importCommands(arguments[1])[0].re)" << "--" << commands, "[object RegExp]\n");
RUN("eval" << "Object.prototype.toString.call(importCommands(arguments[1])[0].wndre)" << "--" << commands, "[object RegExp]\n");
RUN("eval" << "importCommands(arguments[1])[0].re" << "--" << commands, "/x/\n");
RUN("eval" << "importCommands(arguments[1])[0].re" << "--" << commands, "/^(https?|ftps?):\\/\\/\\$/\n");
RUN("eval" << "importCommands(arguments[1])[0].wndre" << "--" << commands, "/(?:)/\n");

RUN("eval" << "addCommands(importCommands(arguments[1]))" << "--" << commands, "");
RUN("keys" << commandDialogListId << "Enter" << clipboardBrowserId, "");

RUN("exportCommands(commands())", commands);
RUN("commands()[0].name", "\n");
RUN("commands()[0].re", "/x/\n");
RUN("commands()[0].re", "/^(https?|ftps?):\\/\\/\\$/\n");
RUN("commands()[0].wndre", "/(?:)/\n");
}

Expand Down

0 comments on commit afaf92c

Please sign in to comment.