Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Unescaped dataDir path in start.mjs #97

Merged
merged 1 commit into from
Jan 12, 2024
Merged

Fix: Unescaped dataDir path in start.mjs #97

merged 1 commit into from
Jan 12, 2024

Conversation

ChenglongMa
Copy link
Contributor

Hi,

Bug Description

In zotero-cmd.json, we are required to set the dataDir of Zotero, like:

  "exec": {
    "dataDir": "C:\\Zotero\\Data"
  }

In Win32 platform, the value will be converted to "C:\Zotero\Data" in start.mjs, which is invalid in prefs.js and thus will be reverted to Zotero's default value: C:\Users\<USERNAME>\Zotero.

Solutions

To fix or avoid this error, there are two solutions:

  1. Set dataDir with 4 \, i.e.,
"exec": {
  "dataDir": "C:\\\\Zotero\\\\Data"
}
  1. Use regex to convert dataDir to the correct form [Recommended]
    As shown in this PR, just add .replace(/\\\\?/g, "\\\\") in

    return `user_pref("extensions.zotero.dataDir", "${dataDir}");`;

    It can convert both \\ or \\\\ to \\ automatically.

Thanks!

@volatile-static
Copy link
Contributor

Why C:\\Zotero\\Data instead of C:\Zotero\Data?

@northword
Copy link
Collaborator

Why C:\\Zotero\\Data instead of C:\Zotero\Data?

反斜线转义


我倾向于第二种方案

@windingwind windingwind merged commit 2cc3ac7 into windingwind:main Jan 12, 2024
@volatile-static
Copy link
Contributor

Why C:\\Zotero\\Data instead of C:\Zotero\Data?

反斜线转义

我倾向于第二种方案

我没看懂这里为什么需要转义?我之前在这用没发现什么问题啊

@northword
Copy link
Collaborator

我没看懂这里为什么需要转义?我之前在这用没发现什么问题啊

image

image

@volatile-static
Copy link
Contributor

我没看懂这里为什么需要转义?我之前在这用没发现什么问题啊

image

image

不是,这图里只是转义了一次啊,pr的不是4个反斜杠吗

@northword
Copy link
Collaborator

northword commented Jan 12, 2024

不是,这图里只是转义了一次啊,pr的不是4个反斜杠吗

转义一次是 \\,这是脚本可读的,脚本读到的是 \,所以存入 prefs.js 的是 \
而存入 prefs.js 的也需要是 \\,所以脚本读到的也需要是 \\,所以要填 \\\\

这样不直观,所以在脚本里加了替换,实际输入的时候仍只输入 \\ 就好。

@ChenglongMa
Copy link
Contributor Author

不是,这图里只是转义了一次啊,pr的不是4个反斜杠吗

转义一次是 \\,这是脚本可读的,脚本读到的是 \,所以存入脚本的是 \; 而存入 prefs.js 的也需要是 \\,所以脚本读到的也需要是 \\,所以要填 \\\\

这样不直观,所以在脚本里加了替换,实际输入的时候仍只输入 \\ 就好。

是的,正是这个意思。感谢解释!

@ChenglongMa ChenglongMa deleted the patch-1 branch January 12, 2024 03:24
@volatile-static
Copy link
Contributor

哦,我不知道这里是存prefs的,打扰了

Copy link

github-actions bot commented May 3, 2024

🚀 This ticket has been resolved in v1.1.2. See Release 1.1.2 for release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants