Skip to content

Commit

Permalink
Merge pull request #41885 from LakshanWeerasinghe/fix-#41878
Browse files Browse the repository at this point in the history
Fix accessing resource-path-name with escaped dot characters
  • Loading branch information
KavinduZoysa authored Jan 19, 2024
2 parents 4685f5b + 4c8db89 commit d9fc725
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,9 @@ public static String generateReturnType(BType bType) {
static String cleanupObjectTypeName(String typeName) {
int index = typeName.lastIndexOf("."); // Internal type names can contain dots hence use the `lastIndexOf`
int typeNameLength = typeName.length();
if (index > 0 && index != typeNameLength - 1) { // Resource method name can contain . at the end
if (index > 1 && typeName.charAt(index - 1) == '\\') { // Methods can contain escaped characters
return typeName;
} else if (index > 0 && index != typeNameLength - 1) { // Resource method name can contain . at the end
return typeName.substring(index + 1);
} else if (index > 0) {
// We will reach here for resource methods eg: (MyClient8.$get$.)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public Object[][] testClientResourceAccessActionData() {
{"testResourceAccessOfAnObjectConstructedViaObjectCons"},
{"testResourceAccessContainingSpecialChars"},
{"testClosuresFromPathParams"},
{"testAccessingResourceWithIncludedRecordParam"}
{"testAccessingResourceWithIncludedRecordParam"},
{"testAccessingResourceWithEscapedChars"}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,55 @@ function testAccessingResourceWithIncludedRecordParam() {
assertEquality(d, 3);
}

client class Client11 {
resource function get v1\.2/greeting1() returns string {
return "Path1";
}

resource function get ["v1.2"]/greeting2() returns string {
return "Path2";
}

resource function get v1\.2/ab\.c/greeting3() returns string {
return "Path3";
}

resource function get v1\.\.2() returns string {
return "Path4";
}

function abc\.abc() returns string {
return "abc.abc";
}
}

function testAccessingResourceWithEscapedChars() {
Client11 cl = new;
string a1 = cl->/v1\.2/greeting1;
assertEquality(a1, "Path1");

string a2 = cl->/["v1.2"]/greeting1;
assertEquality(a2, "Path1");

string b1 = cl->/["v1.2"]/greeting2;
assertEquality(b1, "Path2");

string b2 = cl->/v1\.2/greeting2;
assertEquality(b2, "Path2");

string c1 = cl->/v1\.2/ab\.c/greeting3;
assertEquality(c1, "Path3");

string c2 = cl->/["v1.2"]/["ab.c"]/greeting3;
assertEquality(c2, "Path3");

string d1 = cl->/v1\.\.2;
assertEquality(d1, "Path4");

string e1 = cl.abc\.abc();
assertEquality(e1, "abc.abc");
}

function assertEquality(any|error actual, any|error expected) {
if expected is anydata && actual is anydata && expected == actual {
return;
Expand Down

0 comments on commit d9fc725

Please sign in to comment.