From f04e576fc158bd8cc573b88858a0ae25ee27f282 Mon Sep 17 00:00:00 2001 From: Mj Alavi Date: Wed, 26 Feb 2025 12:55:49 +1300 Subject: [PATCH 1/3] Update Appium.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed #4865 Enhancement: Prevent Double Slashes in Appium Endpoint URL Overview: This update improves the _buildAppiumEndpoint() function by ensuring the path does not end with a trailing slash. This prevents potential issues with double slashes when constructing the Appium REST API endpoint URL. Changes: Introduced normalizedPath, which removes a trailing slash from path using .replace(/\/$/, ''). Updated the return statement to use normalizedPath instead of path. Benefits: ✅ Prevents malformed URLs with double slashes. ✅ Improves consistency and reliability of API requests. ✅ Enhances code readability and maintainability. --- lib/helper/Appium.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/helper/Appium.js b/lib/helper/Appium.js index 2519d68eb..eb26ca56f 100644 --- a/lib/helper/Appium.js +++ b/lib/helper/Appium.js @@ -383,8 +383,10 @@ class Appium extends Webdriver { _buildAppiumEndpoint() { const { protocol, port, hostname, path } = this.browser.options + // Ensure path does NOT end with a slash to prevent double slashes + const normalizedPath = path.replace(/\/$/, ''); // Build path to Appium REST API endpoint - return `${protocol}://${hostname}:${port}${path}/session/${this.browser.sessionId}` + return `${protocol}://${hostname}:${port}${normalizedPath}/session/${this.browser.sessionId}` } /** From 39bc0098876aadc8319d1926fb3425b7ebde869c Mon Sep 17 00:00:00 2001 From: Mj Alavi Date: Wed, 26 Feb 2025 13:00:19 +1300 Subject: [PATCH 2/3] Update container.js Fixed #4863 --- lib/container.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/container.js b/lib/container.js index 66c7c1610..886e42078 100644 --- a/lib/container.js +++ b/lib/container.js @@ -469,7 +469,7 @@ function loadGherkinSteps(paths) { loadSupportObject(path, `Step Definition from ${path}`) } } else { - const folderPath = paths.startsWith('.') ? path.join(global.codecept_dir, paths) : '' + const folderPath = paths.startsWith('.') ? normalizeAndJoin(global.codecept_dir, paths) : '' if (folderPath !== '') { globSync(folderPath).forEach(file => { loadSupportObject(file, `Step Definition from ${file}`) @@ -562,3 +562,16 @@ function getHelperModuleName(helperName, config) { // built-in helpers return `./helper/${helperName}` } + +function normalizeAndJoin(basePath, subPath) { + // Normalize the path (handles extra slashes and resolves `..`) + let normalizedBase = path.normalize(basePath); + let normalizedSub = path.normalize(subPath); + + // Replace backslashes with forward slashes + normalizedBase = normalizedBase.replace(/\\/g, '/'); + normalizedSub = normalizedSub.replace(/\\/g, '/'); + + // Join the paths using POSIX-style + return path.posix.join(normalizedBase, normalizedSub); +} \ No newline at end of file From 5ad7f5a2a78507ef1aee595090920dd7eb0fc541 Mon Sep 17 00:00:00 2001 From: Mj Alavi <41288915+mjalav@users.noreply.github.com> Date: Tue, 4 Mar 2025 14:43:20 +1300 Subject: [PATCH 3/3] Update lib/container.js Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com> --- lib/container.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/container.js b/lib/container.js index 886e42078..badc08ad9 100644 --- a/lib/container.js +++ b/lib/container.js @@ -562,16 +562,16 @@ function getHelperModuleName(helperName, config) { // built-in helpers return `./helper/${helperName}` } - function normalizeAndJoin(basePath, subPath) { - // Normalize the path (handles extra slashes and resolves `..`) - let normalizedBase = path.normalize(basePath); - let normalizedSub = path.normalize(subPath); + // Normalize and convert slashes to forward slashes in one step + const normalizedBase = path.posix.normalize(basePath.replace(/\\/g, '/')) + const normalizedSub = path.posix.normalize(subPath.replace(/\\/g, '/')) - // Replace backslashes with forward slashes - normalizedBase = normalizedBase.replace(/\\/g, '/'); - normalizedSub = normalizedSub.replace(/\\/g, '/'); + // If subPath is absolute (starts with "/"), return it as the final path + if (normalizedSub.startsWith('/')) { + return normalizedSub + } // Join the paths using POSIX-style - return path.posix.join(normalizedBase, normalizedSub); + return path.posix.join(normalizedBase, normalizedSub) } \ No newline at end of file