Skip to content

Commit 205b30d

Browse files
committed
Add NUL byte removal to resolveFrom as well
1 parent 8301032 commit 205b30d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/tailwindcss-language-server/src/util/resolveFrom.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,17 @@ export function resolveFrom(from?: string, id?: string): string {
5656

5757
let result = resolver.resolveSync({}, from, id)
5858
if (result === false) throw Error()
59+
60+
// The `enhanced-resolve` package supports resolving paths with fragment
61+
// identifiers. For example, it can resolve `foo/bar#baz` to `foo/bar.js`
62+
// However, it's also possible that a path contains a `#` character as part
63+
// of the path itself. For example, `foo#bar` might point to a file named
64+
// `foo#bar.js`. The resolver distinguishes between these two cases by
65+
// escaping the `#` character with a NUL byte when it's part of the path.
66+
//
67+
// Since the real path doesn't actually contain NUL bytes, we need to remove
68+
// them to get the correct path otherwise readFileSync will throw an error.
69+
result = result.replace(/\0(.)/g, '$1')
70+
5971
return result
6072
}

0 commit comments

Comments
 (0)