const bun = @import("bun"); const string = bun.string; const Output = bun.Output; const Global = bun.Global; const Environment = bun.Environment; const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const C = bun.C; const std = @import("std"); const Allocator = std.mem.Allocator; const ComptimeStringMap = @import("../comptime_string_map.zig").ComptimeStringMap; // https://github.com/Vexu/zuri/blob/master/src/zuri.zig#L61-L127 pub const PercentEncoding = struct { /// possible errors for decode and encode pub const EncodeError = error{ InvalidCharacter, OutOfMemory, }; /// returns true if c is a hexadecimal digit pub fn isHex(c: u8) bool { return switch (c) { '0'...'9', 'a'...'f', 'A'...'F' => true, else => false, }; } /// returns true if str starts with a valid path character or a percent encoded octet pub fn isPchar(str: []const u8) bool { if (comptime Environment.allow_assert) std.debug.assert(str.len > 0); return switch (str[0]) { 'a'...'z', 'A'...'Z', '0'...'9', '-', '.', '_', '~', '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=', ':', '@' => true, '%' => str.len > 3 and isHex(str[1]) and isHex(str[2]), else => false, }; } /// decode path if it is percent encoded pub fn decode(allocator: Allocator, path: []const u8) EncodeError!?[]u8 { var ret: ?[]u8 = null; errdefer if (ret) |some| allocator.free(some); var ret_index: usize = 0; var i: usize = 0; while (i < path.len) : (i += 1) { if (path[i] == '%') { if (!isPchar(path[i..])) { return error.InvalidCharacter; } if (ret == null) { ret = try allocator.alloc(u8, path.len); bun.copy(u8, ret, path[0..i]); ret_index = i; } // charToDigit can't fail because the chars are validated earlier var new = (std.fmt.charToDigit(path[i + 1], 16) catch unreachable) << 4; new |= std.fmt.charToDigit(path[i + 2], 16) catch unreachable; ret.?[ret_index] = new; ret_index += 1; i += 2; } else if (path[i] != '/' and !isPchar(path[i..])) { return error.InvalidCharacter; } else if (ret != null) { ret.?[ret_index] = path[i]; ret_index += 1; } } if (ret) |some| return allocator.shrink(some, ret_index); return null; } }; pub const MimeType = enum { Unsupported, TextCSS, TextJavaScript, ApplicationJSON, pub const Map = ComptimeStringMap(MimeType, .{ .{ "text/css", MimeType.TextCSS }, .{ "text/javascript", MimeType.TextJavaScript }, .{ "application/json", MimeType.ApplicationJSON }, }); pub fn decode(str: string) MimeType { // Remove things like ";charset=utf-8" var mime_type = str; if (strings.indexOfChar(mime_type, ';')) |semicolon| { mime_type = mime_type[0..semicolon]; } return Map.get(mime_type) orelse MimeType.Unsupported; } }; pub const DataURL = struct { mime_type: string, data: string, is_base64: bool = false, pub fn parse(url: string) ?DataURL { if (!strings.startsWith(url, "data:")) { return null; } const comma = strings.indexOfChar(url, ',') orelse return null; var parsed = DataURL{ .mime_type = url["data:".len..comma], .data = url[comma + 1 .. url.len], }; if (strings.endsWith(parsed.mime_type, ";base64")) { parsed.mime_type = parsed.mime_type[0..(parsed.mime_type.len - ";base64".len)]; parsed.is_base64 = true; } return parsed; } pub fn decode_mime_type(d: DataURL) MimeType { return MimeType.decode(d.mime_type); } }; rror-inlining'>dylan/fix-error-inlining Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/docs/api/html-rewriter.md (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-08-08worker tests (#4058)Gravatar dave caruso 7-15/+83
2023-08-08feat(bun/test): Implement "toSatisfy" & "toIncludeRepeated" (fwup) (#3651)Gravatar Tiramify (A.K. Daniel) 6-2/+367
2023-08-08Set exports to {} in user-constructed CommonJSModuleRecords (#4076)Gravatar dave caruso 2-1/+8
2023-08-08Fix require("console") #3820 (#4073)Gravatar dave caruso 3-2/+9
2023-08-08Update Worker.cppGravatar Dylan Conway 1-1/+0
2023-08-081. Check if the argument is an empty string in `path.format`. (#4064)Gravatar Ai Hoshino 2-67/+213
2023-08-08import bun (#4055)Gravatar Jarred Sumner 8-18/+61
2023-08-08Enable `Headers.prototype.getSetCookie`Gravatar Jarred Sumner 2-25/+11
2023-08-08Remove printfGravatar Jarred Sumner 1-1/+0
2023-08-07Add `env` option for `node:worker_threads` (#4052)Gravatar dave caruso 23-185/+723
2023-08-07Fix `Bun.hash` functions (#4054)Gravatar jhmaster 4-37/+42
2023-08-07fix `worker.ref()`Gravatar Dylan Conway 1-1/+1
2023-08-07add bun update to help menuGravatar Jarred Sumner 1-0/+2
2023-08-07implement fetching data urls (#4000)Gravatar Dylan Conway 10-21/+244
2023-08-07implement `bun update` (#4046)Gravatar Alex Lam S.L 5-89/+389
2023-08-07fix iterating headers with `set-cookie` (#4048)Gravatar Dylan Conway 5-53/+51
2023-08-07WASM test analyzer (#4043)Gravatar Jarred Sumner 25-169/+965
2023-08-07Improve plugin docsGravatar Colin McDonnell 3-306/+283
2023-08-07Fix `path.normalize` edge case. (#4042)Gravatar Ai Hoshino 2-1/+2
2023-08-06Fixes #4001 (#4034)Gravatar Jarred Sumner 3-9/+108
2023-08-06Fixes #4029 and fixes #4022 (#4032)Gravatar Jarred Sumner 4-29/+34
2023-08-06Fixes #4010 (#4031)Gravatar Jarred Sumner 1-24/+17
2023-08-06Update build-idGravatar Jarred Sumner 1-1/+1
2023-08-06Bind require.resolve() (#4030)Gravatar Jarred Sumner 4-13/+47
2023-08-06Fixes #4020Gravatar Jarred Sumner 2-1/+6
2023-08-06Running missing scripts exits with non-0 (#4026)Gravatar Yash Sharma 2-1/+13
2023-08-06[install] handle `bun add` of existing `peerDependencies` correctly (#4028)Gravatar Alex Lam S.L 3-22/+98
2023-08-06fix nanbun-v0.7.3Gravatar Jarred Sumner 1-0/+3
2023-08-06Update coverage.mdGravatar Jarred Sumner 1-1/+1
2023-08-06Update lol-htmlGravatar Jarred Sumner 1-0/+0
2023-08-06Fixes #3129 (#4018)Gravatar Jarred Sumner 3-104/+58
2023-08-06Code coverage for `bun test` (#3975)Gravatar Jarred Sumner 32-61/+1211
2023-08-06feat: impl `dns.getServers` (#3982)Gravatar Ai Hoshino 5-3/+135
2023-08-06Implement --test-name-pattern (#3998)Gravatar dave caruso 8-7/+151
2023-08-05Fix(cli/init): support subpath entrypoint. (#4002)Gravatar Ai Hoshino 1-1/+8
2023-08-05Remove Bun.plugin transpiler hook, encourage usage of `--preload` instead (#3...Gravatar dave caruso 5-243/+1
2023-08-04Support --dev/-D and support more flags on bun install (#3989)Gravatar Colin McDonnell 5-9/+14
2023-08-04fix macro string escaping (#3967)Gravatar Dylan Conway 4-8/+97
2023-08-04Fixes #3991Gravatar Jarred Sumner 2-4/+40
2023-08-04[install] handle `workspace:*` correctly (#3994)Gravatar Alex Lam S.L 2-54/+158
2023-08-04Update import-meta.mdGravatar Jarred Sumner 1-2/+1
2023-08-04Fix incorrect docsGravatar Jarred Sumner 1-2/+3
2023-08-04[types] fix `blob.json()` (#3995)Gravatar Alex Lam S.L 1-4/+4
2023-08-04FFI typo (#3973)Gravatar dave caruso 3-5/+10
2023-08-04Buffer.copy should ignore out-of-range sourceEnd (#3971)Gravatar Yifei Wang 2-17/+34
2023-08-04[install] store resolved workspace path in lockfile (#3974)Gravatar Alex Lam S.L 5-82/+187
2023-08-04Fix types (#3963)Gravatar Colin McDonnell 14-274/+892
2023-08-04feat(hot-clear-screen): clear terminal on hot reload (#3976)Gravatar simylein 1-0/+7