-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from imgproxy/fix-url-safe-encoding
Added symbol replacement when encoding URLs
- Loading branch information
Showing
6 changed files
with
47 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import bufferToBase64 from "./bufferToBase64"; | ||
|
||
describe("bufferToBase64", () => { | ||
it("should return a base64 string", () => { | ||
const result = bufferToBase64(Buffer.from("Hello, World!")); | ||
|
||
expect(result).toBe("SGVsbG8sIFdvcmxkIQ"); | ||
}); | ||
|
||
it("should return a base64 string without padding", () => { | ||
const result = bufferToBase64(Buffer.from("Hello, World!")); | ||
|
||
expect(result).not.toContain("="); | ||
}); | ||
|
||
it("should return a base64 string with - instead of +", () => { | ||
const result = bufferToBase64(Buffer.from("Hello World!")); | ||
|
||
expect(result).not.toContain("+"); | ||
}); | ||
|
||
it("should return a base64 string with _ instead of /", () => { | ||
const result = bufferToBase64(Buffer.from("attached/attachment.jpg")); | ||
|
||
expect(result).not.toContain("/"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const bufferToBase64 = (buffer: Buffer): string => { | ||
return buffer | ||
.toString("base64") | ||
.replace(/=/g, "") | ||
.replace(/\+/g, "-") | ||
.replace(/\//g, "_"); | ||
}; | ||
|
||
export default bufferToBase64; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters