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

Support for utf8 bodies #124

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/entries/Background/plugins/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { addPlugin, addPluginConfig, addPluginMetadata } from '../db';
import { getPluginConfig } from '../../../utils/misc';
import { bytesSize, indexOfString } from '../../../utils/utf8';

export async function installPlugin(
urlOrBuffer: ArrayBuffer | string,
origin = '',
filePath = '',
metadata: {[key: string]: string} = {},
metadata: { [key: string]: string } = {},
) {
let arrayBuffer;

Expand All @@ -31,11 +32,11 @@ export async function installPlugin(
export function mapSecretsToRange(secrets: string[], text: string) {
return secrets
.map((secret: string) => {
const index = text.indexOf(secret);
return index > -1
const byteIdx = indexOfString(text, secret);
return byteIdx > -1
? {
start: index,
end: index + secret.length,
start: byteIdx,
end: byteIdx + bytesSize(secret)
}
: null;
})
Expand Down
7 changes: 7 additions & 0 deletions src/utils/utf8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function indexOfString(str: string, substr: string): number {
return Buffer.from(str).indexOf(Buffer.from(substr));
}

export function bytesSize(str: string): number {
return Buffer.from(str).byteLength;
}