From fca988cea1383e42d599300edab71591dd4134b2 Mon Sep 17 00:00:00 2001 From: Jimmy Liu Jia <91264074+JimmyLiuJia@users.noreply.github.com> Date: Wed, 4 Nov 2026 01:43:54 +0800 Subject: [PATCH] fix(appsync): scan template holes and keyword object keys (#7320) Exempt a banned keyword from the APPSYNC_JS subset scan only in an object-key position, after a { or , and before its :, so { class: "allowed" } runs while cond ? this : null is still refused. Adds regression cases for template text after a hole, whose scanning landed in #7343. Closes #7240 --- .../resources/appsync/appsync-js-runtime.mjs | 8 ++- ...ppSyncJsResolverDockerIntegrationTest.java | 59 +++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/main/resources/appsync/appsync-js-runtime.mjs b/src/main/resources/appsync/appsync-js-runtime.mjs index a350d26377..99e6949369 100644 --- a/src/main/resources/appsync/appsync-js-runtime.mjs +++ b/src/main/resources/appsync/appsync-js-runtime.mjs @@ -745,8 +745,12 @@ function validateAppSyncSubset(code) { const literals = blankLiterals(code); const lineNumber = (index) => code.slice(0, index).split(/\r\n|[\r\n\u2028\u2029]/).length; for (const [pattern, description] of BANNED_CONSTRUCTS) { - const match = pattern.exec(literals.scanned); - if (match) { + for (const match of literals.scanned.matchAll(new RegExp(pattern.source, 'g'))) { + const before = literals.scanned.slice(0, match.index).trimEnd(); + const after = literals.scanned.slice(match.index + match[0].length); + if (/^[\w$]+$/.test(match[0]) && /[,{]$/.test(before) && /^\s*:/.test(after)) { + continue; + } return unsupportedConstruct(description, lineNumber(match.index)); } } diff --git a/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncJsResolverDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncJsResolverDockerIntegrationTest.java index d65f966e8b..6ad34c7252 100644 --- a/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncJsResolverDockerIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncJsResolverDockerIntegrationTest.java @@ -58,6 +58,9 @@ class AppSyncJsResolverDockerIntegrationTest { misplacedYield: String malformedSyntax: String keywordsInText: String + templateHole: String + keywordObjectKey: String + conditionalThis: String regexLiteral: String regexKeyword: String regexClassThenUnsupported: String @@ -220,6 +223,34 @@ class AppSyncJsResolverDockerIntegrationTest { } """; + private static final String TEMPLATE_HOLE_RESOLVER = """ + export function request(ctx) { + const prefix = `${"value"}-`; + return { payload: { value: `its class: ${prefix}` } }; + } + export function response(ctx) { + return ctx.result.value; + } + """; + + private static final String KEYWORD_OBJECT_KEY_RESOLVER = """ + export function request(ctx) { + return { payload: { class: "allowed" } }; + } + export function response(ctx) { + return ctx.result.class; + } + """; + + private static final String CONDITIONAL_THIS_RESOLVER = """ + export function request(ctx) { + return { payload: ctx.args.flag ? this : null }; + } + export function response(ctx) { + return ctx.result; + } + """; + private static final String REGEX_KEYWORD_RESOLVER = """ export function request(ctx) { return { payload: { value: /while/.test("while") } }; @@ -381,6 +412,9 @@ class AppSyncJsResolverDockerIntegrationTest { createUnitResolver(apiId, "Query", "misplacedYield", "local", YIELD_RESOLVER); createUnitResolver(apiId, "Query", "malformedSyntax", "local", MALFORMED_RESOLVER); createUnitResolver(apiId, "Query", "keywordsInText", "local", KEYWORDS_IN_TEXT_RESOLVER); + createUnitResolver(apiId, "Query", "templateHole", "local", TEMPLATE_HOLE_RESOLVER); + createUnitResolver(apiId, "Query", "keywordObjectKey", "local", KEYWORD_OBJECT_KEY_RESOLVER); + createUnitResolver(apiId, "Query", "conditionalThis", "local", CONDITIONAL_THIS_RESOLVER); createUnitResolver(apiId, "Query", "regexLiteral", "local", REGEX_LITERAL_RESOLVER); createUnitResolver(apiId, "Query", "regexKeyword", "local", REGEX_KEYWORD_RESOLVER); createUnitResolver(apiId, "Query", "regexClassThenUnsupported", "local", @@ -597,6 +631,31 @@ class AppSyncJsResolverDockerIntegrationTest { .body("data.keywordsInText", equalTo("try catch class while ok")); } + @Test + void aTemplateLiteralResumesAfterItsExpression() { + query("{ templateHole }") + .statusCode(200) + .body("errors", nullValue()) + .body("data.templateHole", equalTo("its class: value-")); + } + + @Test + void aKeywordUsedAsAnObjectKeyIsNotReadAsADeclaration() { + query("{ keywordObjectKey }") + .statusCode(200) + .body("errors", nullValue()) + .body("data.keywordObjectKey", equalTo("allowed")); + } + + @Test + void aConditionalThisBeforeAColonIsStillRefused() { + query("{ conditionalThis }") + .statusCode(200) + .body("data.conditionalThis", nullValue()) + .body("errors[0].errorType", equalTo("UnsupportedFeature")) + .body("errors[0].message", containsString("this")); + } + @Test void aRegexLiteralIsReportedAsUnsupported() { query("{ regexLiteral }")