Skip to content

Commit

Permalink
Pretty Quote Error (#7129)
Browse files Browse the repository at this point in the history
* Starter Commit

* Cleanup

* Change to Error

Error instead of warn

* Test

* More Tests

* Test Update

* Remove -

---------

Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
Co-authored-by: Moderocky <admin@moderocky.com>
Co-authored-by: Efnilite <35348263+Efnilite@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 23, 2024
1 parent 75d0701 commit fde4408
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/ch/njol/skript/lang/SkriptParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ public boolean hasTag(String tag) {
}

private static @Nullable Expression<?> parseExpression(Class<?>[] types, String expr) {;
if (expr.startsWith("“") || expr.startsWith("”") || expr.endsWith("”") || expr.endsWith("“")) {
Skript.error("Pretty quotes are not allowed, change to regular quotes (\")");
return null;
}
if (expr.startsWith("\"") && expr.length() != 1 && nextQuote(expr, 1) == expr.length() - 1) {
return VariableString.newInstance("" + expr.substring(1, expr.length() - 1));
} else {
Expand Down
30 changes: 30 additions & 0 deletions src/test/skript/tests/misc/pull-7129-pretty-quotes.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

command /prettyquotecommandtest “prettyquoteliteral” <text>:
trigger:
set {PrettyQuoteArg} to arg

test "pretty quote usage":
set {_error} to "Pretty quotes are not allowed, change to regular quotes"
parse:
set {_test} to "“Embedded Pretty Quotes”"
assert last parse logs does not contain {_error} with "Pretty quotes should work inside strings"

parse:
set {_test} to "" #“Pretty Quote Comment”
assert last parse logs does not contain {_error} with "Pretty quotes should work in comments"

parse:
set {_test“”} to ""
assert last parse logs does not contain {_error} with "Pretty quotes should work in var names"

parse:
set {_test} to “Pretty Quotes”
assert last parse logs contain {_error} with "Pretty quote string usage did not produce expected error"

parse:
set {_test} to "test%“test”%"
assert last parse logs contain {_error} with "Pretty quote %%string%% usage did not produce expected error"

execute command "prettyquotecommandtest “prettyquoteliteral” “prettyquotearg”"
assert {PrettyQuoteArg} is "“prettyquotearg”" with "Pretty quotes should work in command args"
clear {PrettyQuoteArg}

0 comments on commit fde4408

Please sign in to comment.