Skip to content

Commit

Permalink
escape paths when generating resources
Browse files Browse the repository at this point in the history
  • Loading branch information
vanyauhalin committed Jul 5, 2024
1 parent 77013bb commit c0bc1e4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/library-resource/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {readFile} from "node:fs/promises"
import {join} from "node:path"
import {URL, fileURLToPath} from "node:url"
import type {Declaration} from "@onlyoffice/library-declaration"
import {escape} from "@onlyoffice/node-path/win32.ts"

export interface Resource {
list(): Declaration[]
Expand All @@ -15,10 +16,10 @@ export async function resource(df: string, mf: string): Promise<string> {
let rc = await readFile(rf, "utf8")

const d = "const d: Declaration[] = require"
rc = rc.replace(`${d}("")`, `${d}("${df}")`)
rc = rc.replace(`${d}("")`, `${d}("${escape(df)}")`)

const m = "const m: Record<string, number> = require"
rc = rc.replace(`${m}("")`, `${m}("${mf}")`)
rc = rc.replace(`${m}("")`, `${m}("${escape(mf)}")`)

return rc
}
Expand Down
1 change: 1 addition & 0 deletions packages/library-resource/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@onlyoffice/library-declaration": "workspace:^",
"@onlyoffice/node-path": "workspace:^",
"@types/node": "^20.12.12",
"typescript": "^5.4.5"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/service-resource/lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {readFile} from "node:fs/promises"
import {join} from "node:path"
import {URL, fileURLToPath} from "node:url"
import {escape} from "@onlyoffice/node-path/win32.ts"
import type {Component, Declaration} from "@onlyoffice/service-declaration"

export interface Resource {
Expand All @@ -26,10 +27,10 @@ export async function resource(df: string, cf: string): Promise<string> {
let rc = await readFile(rf, "utf8")

const d = "const d: Declaration[] = require"
rc = rc.replace(`${d}("")`, `${d}("${df}")`)
rc = rc.replace(`${d}("")`, `${d}("${escape(df)}")`)

const c = "const c: Record<string, Component> = require"
rc = rc.replace(`${c}("")`, `${c}("${cf}")`)
rc = rc.replace(`${c}("")`, `${c}("${escape(cf)}")`)

return rc
}
Expand Down
1 change: 1 addition & 0 deletions packages/service-resource/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"test": "pnpm test:types && pnpm test:unit"
},
"dependencies": {
"@onlyoffice/node-path": "workspace:^",
"@onlyoffice/service-declaration": "workspace:^",
"@types/node": "^20.12.12",
"typescript": "^5.4.5"
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c0bc1e4

Please sign in to comment.