Skip to content

Export highlights: secure export filename - #14325

Merged
hius07 merged 5 commits into
koreader:masterfrom
hius07:export-secure-filepath
Sep 15, 2025
Merged

Export highlights: secure export filename#14325
hius07 merged 5 commits into
koreader:masterfrom
hius07:export-secure-filepath

Conversation

@hius07

@hius07 hius07 commented Sep 14, 2025

Copy link
Copy Markdown
Member

@hius07 hius07 added the Plugin label Sep 14, 2025
Comment thread plugins/exporter.koplugin/main.lua Outdated
-- full file path without extension
clipping_filepath = clipping_dir .. "/" ..
util.getSafeFilename(self.ui.bookinfo:expandString(clipping_filename, file, timestamp), nil, nil, -1)
clipping_filepath = clipping_filepath:gsub("[\n\r]", ", "):gsub("\t", " ")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to handle it in getSafeFilename so you can pass a string with a newline in it. I could see a similar problem inadvertently coming from OPDS or NewsDownloader or something, or perhaps user input. Of course special behavior like replacing newline with , would then have to be done first.

Incidentally, wouldn't a Windows \r\n become , , as written?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

special behavior like replacing newline with ,

What is the common behaviour? Replace with the white space?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's likely the most common but I also think it makes the most sense generically. This particular replacement is tailored to a list, but that wouldn't apply to a title like:

Moby-Dick
or, The Whale

Or any other assortment of lines that don't form a list.

Incidentally, I believe that ; is acceptable, so it's probably better than , for the use case (Author, Firstname; Author2, Firstname2)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For book info we use the pipeline

tvalue = tvalue:gsub("[\n\t]", "|")

Is it good in filenames?

@Frenzie Frenzie Sep 14, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's one of the forbidden Windows characters. ;-)

Edit: see util.replaceAllInvalidChars()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, to summarize:
-in export, \n and \r\n are replaced with ;
-in util, \n and \r\n and \t are replaced with space
Right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makes the most sense, yes.

Comment thread frontend/util.lua Outdated
---- @treturn string safe filename
function util.getSafeFilename(str, path, limit, limit_ext)
local filename, suffix = util.splitFileNameSuffix(str)
filename = filename:gsub("\r?\n", " "):gsub("\t", " ")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense conceptually around line 1010 (just before the length limit)? Fine by me either way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

@hius07
hius07 merged commit 0bea354 into koreader:master Sep 15, 2025
4 checks passed
@hius07
hius07 deleted the export-secure-filepath branch September 15, 2025 14:02
@hius07 hius07 added this to the 2025.10 milestone Sep 15, 2025
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export highlights failed

2 participants