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

Account for possible utf-8 bom in toc files #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

emptyrivers
Copy link

Altoholic (it's always the dinosaur addons) has one in Altoholic.toc:
image

local key, value = line:match("^##%s*([^:%s]+)%s*:%s*(.-)%s*$")
---@diagnostic disable-next-line: err-esc
local _, key, value = line:match("^(\xef?\xbb?\xbf?)##%s*([^:%s]+)%s*:%s*(.-)%s*$")
print(_, key, value)
Copy link
Owner

Choose a reason for hiding this comment

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

you forgot a debug print

@@ -6,10 +6,12 @@ function mod:InjectDependency(lines, dep)
local foundDependencyEntry = false
local foundPerfyMetadata = false
for i, line in ipairs(lines) do
local key, value = line:match("^##%s*([^:%s]+)%s*:%s*(.-)%s*$")
---@diagnostic disable-next-line: err-esc
local _, key, value = line:match("^(\xef?\xbb?\xbf?)##%s*([^:%s]+)%s*:%s*(.-)%s*$")
Copy link
Owner

Choose a reason for hiding this comment

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

the bom itself is unused, can you remove the capture for it?

Copy link

Choose a reason for hiding this comment

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

Since lua patterns do not have non-capturing capture groups, the next best thing might be this?
local key, value = select(2, line:match("^(\xef?\xbb?\xbf?)##%s*([^:%s]+)%s*:%s*(.-)%s*$"))

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.

3 participants