Skip to content

Commit f3cd36e

Browse files
mjalavkobenguyent
andauthored
Resolving path inconsistency in container.js and appium.js (#4866)
* Update Appium.js 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. * Update container.js Fixed #4863 * Update lib/container.js Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com> --------- Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
1 parent c313ef4 commit f3cd36e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/container.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ function loadGherkinSteps(paths) {
469469
loadSupportObject(path, `Step Definition from ${path}`)
470470
}
471471
} else {
472-
const folderPath = paths.startsWith('.') ? path.join(global.codecept_dir, paths) : ''
472+
const folderPath = paths.startsWith('.') ? normalizeAndJoin(global.codecept_dir, paths) : ''
473473
if (folderPath !== '') {
474474
globSync(folderPath).forEach(file => {
475475
loadSupportObject(file, `Step Definition from ${file}`)
@@ -562,3 +562,16 @@ function getHelperModuleName(helperName, config) {
562562
// built-in helpers
563563
return `./helper/${helperName}`
564564
}
565+
function normalizeAndJoin(basePath, subPath) {
566+
// Normalize and convert slashes to forward slashes in one step
567+
const normalizedBase = path.posix.normalize(basePath.replace(/\\/g, '/'))
568+
const normalizedSub = path.posix.normalize(subPath.replace(/\\/g, '/'))
569+
570+
// If subPath is absolute (starts with "/"), return it as the final path
571+
if (normalizedSub.startsWith('/')) {
572+
return normalizedSub
573+
}
574+
575+
// Join the paths using POSIX-style
576+
return path.posix.join(normalizedBase, normalizedSub)
577+
}

lib/helper/Appium.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,10 @@ class Appium extends Webdriver {
383383

384384
_buildAppiumEndpoint() {
385385
const { protocol, port, hostname, path } = this.browser.options
386+
// Ensure path does NOT end with a slash to prevent double slashes
387+
const normalizedPath = path.replace(/\/$/, '');
386388
// Build path to Appium REST API endpoint
387-
return `${protocol}://${hostname}:${port}${path}/session/${this.browser.sessionId}`
389+
return `${protocol}://${hostname}:${port}${normalizedPath}/session/${this.browser.sessionId}`
388390
}
389391

390392
/**

0 commit comments

Comments
 (0)