Skip to content

Commit

Permalink
[DI] Handle different casing in probe file paths (#5188)
Browse files Browse the repository at this point in the history
In case the file path provided by the user is a different casing than
the one actually deployed, the tracer should still be able to match it
and apply the probe.
  • Loading branch information
watson authored Feb 3, 2025
1 parent dbe0b74 commit ee6dbec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/dd-trace/src/debugger/devtools_client/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module.exports = {
findScriptFromPartialPath (path) {
if (!path) return null // This shouldn't happen, but better safe than sorry

path = path.toLowerCase()

const bestMatch = new Array(3)
let maxMatchLength = -1

Expand All @@ -33,7 +35,7 @@ module.exports = {

// Compare characters from the end
while (i >= 0 && j >= 0) {
const urlChar = url[i]
const urlChar = url[i].toLowerCase()
const pathChar = path[j]

// Check if both characters is a path boundary
Expand Down
8 changes: 6 additions & 2 deletions packages/dd-trace/test/debugger/devtools_client/state.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ describe('findScriptFromPartialPath', function () {
it('prefixed with two unknown directories', testPath(`prefix1/prefix2/to/${filename}`))
})

describe('case insensitive', function () {
it('should match if the path is in lowercase', testPath(filename.toLowerCase()))

it('should match if the path is in uppercase', testPath(filename.toUpperCase()))
})

describe('non-matching paths', function () {
it('should not match if only part of a directory matches (at boundary)',
testPathNoMatch(`path/o/${filename}`))
Expand All @@ -73,8 +79,6 @@ describe('findScriptFromPartialPath', function () {
it('should not match if only part of a directory matches (root)', testPathNoMatch(`o/${filename}`))

it('should not match if only part of a file matches', testPathNoMatch(filename.slice(1)))

it('should not match if only difference is the letter casing', testPathNoMatch(filename.toUpperCase()))
})
})

Expand Down

0 comments on commit ee6dbec

Please sign in to comment.