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

implement fetching data urls #4000

Merged
merged 8 commits into from
Aug 8, 2023
Merged

implement fetching data urls #4000

merged 8 commits into from
Aug 8, 2023

Conversation

dylan-conway
Copy link
Member

@dylan-conway dylan-conway commented Aug 5, 2023

What does this PR do?

this adds support for fetching data urls

const res = await fetch("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
console.log(await res.text()); // Hello, World!

How did you verify your code works?

added tests for fetching valid and invalid data urls

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2023

@dylan-conway 4 files with test failures on bun-darwin-aarch64:

  • test/bundler/esbuild/loader.test.ts
  • test/js/bun/spawn/spawn.test.ts
  • test/js/bun/test/test-test.test.ts
  • test/js/node/dns/node-dns.test.js

View test output

#775e1ae0a59e030547ceb66449abb9c3db50778e

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2023

@dylan-conway 2 files with test failures on linux-x64-baseline:

  • test/js/bun/test/test-test.test.ts
  • test/js/third_party/prisma/prisma.test.ts

View test output

#addc89e38347bbd5f0595b4ed211b772fa64a44c

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2023

@dylan-conway 2 files with test failures on linux-x64:

  • test/js/bun/test/test-test.test.ts
  • test/js/third_party/prisma/prisma.test.ts

View test output

#addc89e38347bbd5f0595b4ed211b772fa64a44c

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2023

@dylan-conway 6 files with test failures on bun-darwin-x64-baseline:

  • test/js/bun/spawn/spawn-streaming-stdin.test.ts
  • test/js/bun/sqlite/sqlite.test.js
  • test/js/bun/test/test-test.test.ts
  • test/js/third_party/webpack/webpack.test.ts
  • test/js/web/timers/setInterval.test.js
  • test/js/web/timers/setTimeout.test.js

View test output

#addc89e38347bbd5f0595b4ed211b772fa64a44c

},
},
.allocator = allocator,
.status_text = bun.String.create("OK"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

createAtom

Copy link
Collaborator

Choose a reason for hiding this comment

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

or just .empty

@@ -71,22 +71,28 @@ pub const PercentEncoding = struct {
}
}

if (ret) |some| return allocator.shrink(some, ret_index);
if (ret) |some| return allocator.realloc(some, ret_index) catch unreachable;
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets just not reallocate i don't think its necessary

if (!strings.startsWith(url, "data:")) {
return null;
}

const comma = strings.indexOfChar(url, ',') orelse return null;
var result = try parseWithoutCheck(url);
Copy link
Collaborator

Choose a reason for hiding this comment

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

return try parseWithoutCheck(url);

Copy link
Collaborator

Choose a reason for hiding this comment

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

but it doesn't matter

Copy link
Member Author

Choose a reason for hiding this comment

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

it's actually compiler error, not sure if it's a zig bug

@@ -34,7 +34,7 @@ pub const PercentEncoding = struct {
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]),
'%' => str.len >= 3 and isHex(str[1]) and isHex(str[2]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

@Jarred-Sumner Jarred-Sumner merged commit 2fe6a96 into main Aug 8, 2023
@Jarred-Sumner Jarred-Sumner deleted the dylan/fetch-data-urls branch August 8, 2023 03:15
trnxdev pushed a commit to trnxdev/bun that referenced this pull request Aug 9, 2023
* fetch data urls

* `byteSlice`

* deinit slice

* allocate `mime_type` string if needed

* `content_type_allocated` and uncomment tests

* `str_`

* createAtom and slice decode result
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.

2 participants