fix: correctly parse base64 with whitespace

This commit is contained in:
daimond113 2024-12-09 10:46:25 +01:00
parent 3e22a38dca
commit ad36473326
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C
10 changed files with 9 additions and 18 deletions

View file

@ -167,7 +167,7 @@ for _, binSrc in pathfs.readDir(BINS_SRC_DIR) do
type = "Custom",
payload = {
method = "GET",
url = `https://api.github.com/repos/{repoName}/contents/README.md`,
url = `https://api.github.com/repos/{repoName}/readme`,
},
},
})
@ -181,20 +181,10 @@ for _, binSrc in pathfs.readDir(BINS_SRC_DIR) do
-- NOTE: Github uses a special format for encoding the contents, where it
-- separates the entire file into multiple lines, and encodes each line in
-- base64
local lines = string.split(resp.content, "\n")
local decoded = buffer.create(resp.size)
local cum = 0
for _, line in lines do
if line == "" then
-- Skip empty lines
continue
end
local src = base64.decode(buffer.fromstring(line))
buffer.copy(decoded, math.clamp(cum - 1, 0, math.huge), src)
cum += buffer.len(src)
end
-- This should be done by the base64 library, but oh well
local content = string.gsub(resp.content, "%s+", "")
local decoded = base64.decode(buffer.fromstring(content))
return Result.Ok(decoded)
end
@ -210,6 +200,8 @@ for _, binSrc in pathfs.readDir(BINS_SRC_DIR) do
-- Write the updated README to the tool's directory
local readmeContents = readmeRes:unwrap()
-- There used to be some issues with encoding if not deleted and recreated
pathfs.removeFile(readmePath)
pathfs.writeFile(readmePath, readmeContents)
print(

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,7 +1,7 @@
<div align="center">
<h1>
StyLua<br>
<ahref="https://crates.io/crates/stylua"><img src="https://img.shields.io/crates/v/stylua.svg"></a>
<a href="https://crates.io/crates/stylua"><img src="https://img.shields.io/crates/v/stylua.svg"></a>
<a href="https://github.com/JohnnyMorganz/StyLua/actions/workflows/ci.yml"><img src="https://github.com/JohnnyMorganz/StyLua/actions/workflows/ci.yml/badge.svg"></a>
<a href="https://codecov.io/gh/JohnnyMorganz/StyLua"><img src="https://codecov.io/gh/JohnnyMorganz/StyLua/branch/main/graph/badge.svg"/></a>
</h1>
@ -301,4 +301,3 @@ space_after_function_names = "Never"
[sort_requires]
enabled = false
```

Binary file not shown.

View file

@ -66,8 +66,8 @@ environment = "lune"
lib = "lib/init.luau"
[graph."synpixel/base64"."3.0.1 lune"]
direct = ["base64", { name = "synpixel/base64", version = "^3.0.1" }, "standard"]
resolved_ty = "standard"
direct = ["base64", { name = "synpixel/base64", version = "^3.0.1" }, "dev"]
resolved_ty = "dev"
[graph."synpixel/base64"."3.0.1 lune".target]
environment = "lune"