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

Minimal escaping not applied to shorttitle field for CJK characters #3090

Closed
TomBener opened this issue Nov 29, 2024 · 2 comments
Closed

Minimal escaping not applied to shorttitle field for CJK characters #3090

TomBener opened this issue Nov 29, 2024 · 2 comments
Labels

Comments

@TomBener
Copy link

Debug log ID

HPQUGLX5-refs-apse/6.7.258-7

What happened?

Description

The current code applies minimal escaping to the title field when it contains >10% CJK characters, but this doesn't work for the shorttitle field. This affects entries where both fields contain CJK characters. #2810 is related.

Current Behavior

@article{shenaidi2017,
  shorttitle = {``请捐一分钱给中国小朋友''},
  author = {{沈艾娣}},
  translator = {{蔡丹妮}},
  date = {2017},
  journaltitle = {全球史评论},
  number = {1},
  pages = {176--201, 350},
  title = {“请捐一分钱给中国小朋友”:法国天主教圣婴会在中国(1843--1951年)}
}
  • The title field gets minimal escaping when >10% CJK
  • The shorttitle field still gets full escaping, causing potential issues with CJK characters

Expected Behavior

Both fields should get minimal escaping when they contain >10% CJK characters:

@article{shenaidi2017,
  shorttitle = {“请捐一分钱给中国小朋友”},
  author = {{沈艾娣}},
  translator = {{蔡丹妮}},
  date = {2017},
  journaltitle = {全球史评论},
  number = {1},
  pages = {176--201, 350},
  title = {“请捐一分钱给中国小朋友”:法国天主教圣婴会在中国(1843--1951年)}
}

Current Postscript

if (
  zotero.title &&
  zotero.title.replace(/[^\u4E00-\u9FFF]/g, "").length / zotero.title.length >
    0.1
) {
  tex.add({ name: "title", value: zotero.title, enc: "minimal" });
}

if (
  zotero.shorttitle &&
  zotero.shorttitle.replace(/[^\u4E00-\u9FFF]/g, "").length / zotero.shorttitle.length >
    0.1
) {
  tex.add({ name: "shorttitle", value: zotero.shorttitle, enc: "minimal" });
}
@retorquere
Copy link
Owner

The zotero object has the field shortTitle, not shorttitle. This will work:

if (
  zotero.shortTitle &&
  zotero.shortTitle.replace(/[^\u4E00-\u9FFF]/g, "").length / zotero.shortTitle.length >
    0.1
) {
  tex.add({ name: "shorttitle", value: zotero.shortTitle, enc: "minimal" });
}

but could generalize to:

  for (const field of ["title", "shorttitle"]) {
    const value = tex.has[field]?.value
    if (value && (value.replace(/[^\u4E00-\u9FFF]/g, "").length / value.length) > 0.1) tex.add({ name: field, value, enc: "minimal" });
  }

@TomBener
Copy link
Author

Many thanks. It works perfectly!

@github-actions github-actions bot reopened this Nov 29, 2024
@github-actions github-actions bot removed the reopened label Nov 29, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants