Skip to content

Commit

Permalink
refactor: Encode file path to handle special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
khksamuel committed May 8, 2024
1 parent 7498aae commit b5e0021
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions source/app/service-providers/fsal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,17 @@ export default class FSAL extends ProviderContract {
// Encode the file path to handle special characters
let encodedPath = encodeURI(absPath)

if (await this.isDir(absPath)) {
throw new Error(`[FSAL] Cannot load file ${absPath} as it is a directory`)
if (await this.isDir(encodedPath)) {
throw new Error(`[FSAL] Cannot load file ${encodedPath} as it is a directory`)
}

if (!await this.isFile(absPath)) {
throw new Error(`[FSAL] Cannot load file ${absPath}: Not found`)
if (!await this.isFile(encodedPath)) {
throw new Error(`[FSAL] Cannot load file ${encodedPath}: Not found`)
}

if (hasMdOrCodeExt(absPath)) {
const content = await fs.readFile(absPath, { encoding: 'utf-8' })
if (hasMdOrCodeExt(encodedPath)) {
// Decode the URI before reading the file
const content = await fs.readFile(decodeURI(encodedPath), { encoding: 'utf-8' })
return content
}

Expand All @@ -493,11 +494,11 @@ export default class FSAL extends ProviderContract {
// Encode the file path to handle special characters
let encodedPath = encodeURI(absPath)

if (await this.isDir(absPath)) {
if (await this.isDir(encodedPath)) {
throw new Error(`[FSAL] Cannot load file ${absPath} as it is a directory`)
}

if (!await this.isFile(absPath)) {
if (!await this.isFile(encodedPath)) {
throw new Error(`[FSAL] Cannot load file ${absPath}: Not found`)
}

Expand Down

0 comments on commit b5e0021

Please sign in to comment.