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

fix(std/node): Add base64url encoding support, indexOf, lastIndexOf and includes to Buffer #1636

Merged
merged 13 commits into from Nov 29, 2021
382 changes: 104 additions & 278 deletions node/_buffer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node/_events.js
Expand Up @@ -37,7 +37,7 @@ import {
validateAbortSignal,
validateBoolean,
validateFunction,
} from "./_validators.ts";
} from "./internal/validators.js";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All this renames might seem unnecessary, but this actually solves two problems:

  1. _validators is actually a shim of internal/validators however it was left in that location in the early days of std/node, now it will be easier to find the required functions when porting modules
  2. This solves a circular dependency created between _validators and internal/validators by moving the content of _validators

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, it was bothering me too; good change.

import { spliceOne } from "./_utils.ts";

const kCapture = Symbol("kCapture");
Expand Down
2 changes: 1 addition & 1 deletion node/_next_tick.ts
Expand Up @@ -3,7 +3,7 @@

// deno-lint-ignore-file no-inner-declarations

import { validateCallback } from "./_validators.ts";
import { validateCallback } from "./internal/validators.js";
import { _exiting } from "./_process/process.ts";
import { FixedQueue } from "./_fixed_queue.ts";

Expand Down
2 changes: 1 addition & 1 deletion node/_readline.js
Expand Up @@ -28,7 +28,7 @@ import {
moveCursor,
} from "./internal/readline/callbacks.js";
import { emitKeypressEvents } from "./internal/readline/emitKeypressEvents.js";
import { validateAbortSignal } from "./_validators.ts";
import { validateAbortSignal } from "./internal/validators.js";
import { promisify } from "./_util/_util_promisify.ts";
import { AbortError } from "./_errors.ts";

Expand Down
2 changes: 1 addition & 1 deletion node/_timers.ts
Expand Up @@ -19,7 +19,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

import { validateCallback, validateNumber } from "./_validators.ts";
import { validateCallback, validateNumber } from "./internal/validators.js";
import { ERR_OUT_OF_RANGE } from "./_errors.ts";
import { emitWarning } from "./process.ts";

Expand Down
4 changes: 4 additions & 0 deletions node/_tools/config.json
Expand Up @@ -18,6 +18,8 @@
"test-buffer-arraybuffer.js",
"test-buffer-bytelength.js",
"test-buffer-from.js",
"test-buffer-includes.js",
"test-buffer-indexof.js",
"test-dns-lookup.js",
"test-dns.js",
"test-event-emitter-errors.js",
Expand Down Expand Up @@ -77,6 +79,8 @@
"test-buffer-failed-alloc-typed-arrays.js",
"test-buffer-fakes.js",
"test-buffer-from.js",
"test-buffer-includes.js",
"test-buffer-indexof.js",
Copy link
Member

Choose a reason for hiding this comment

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

nice 👍

"test-buffer-inheritance.js",
"test-buffer-isencoding.js",
"test-buffer-iterator.js",
Expand Down
23 changes: 9 additions & 14 deletions node/_tools/suites/parallel/test-buffer-bytelength.js
Expand Up @@ -98,23 +98,18 @@ assert.strictEqual(Buffer.byteLength('aGkk', 'base64'), 3);
assert.strictEqual(
Buffer.byteLength('bHNrZGZsa3NqZmtsc2xrZmFqc2RsZmtqcw==', 'base64'), 25
);
// TODO(Soremwar)
// Implement base64url encoding for buffer
// base64url
// assert.strictEqual(Buffer.byteLength('aGVsbG8gd29ybGQ', 'base64url'), 11);
// assert.strictEqual(Buffer.byteLength('aGVsbG8gd29ybGQ', 'BASE64URL'), 11);
// assert.strictEqual(Buffer.byteLength('bm9kZS5qcyByb2NrcyE', 'base64url'), 14);
// assert.strictEqual(Buffer.byteLength('aGkk', 'base64url'), 3);
// assert.strictEqual(
// Buffer.byteLength('bHNrZGZsa3NqZmtsc2xrZmFqc2RsZmtqcw', 'base64url'), 25
// );
assert.strictEqual(Buffer.byteLength('aGVsbG8gd29ybGQ', 'base64url'), 11);
assert.strictEqual(Buffer.byteLength('aGVsbG8gd29ybGQ', 'BASE64URL'), 11);
assert.strictEqual(Buffer.byteLength('bm9kZS5qcyByb2NrcyE', 'base64url'), 14);
assert.strictEqual(Buffer.byteLength('aGkk', 'base64url'), 3);
assert.strictEqual(
Buffer.byteLength('bHNrZGZsa3NqZmtsc2xrZmFqc2RsZmtqcw', 'base64url'), 25
);
// special padding
assert.strictEqual(Buffer.byteLength('aaa=', 'base64'), 2);
assert.strictEqual(Buffer.byteLength('aaaa==', 'base64'), 3);
// TODO(Soremwar)
// Implement base64url encoding for buffer
// assert.strictEqual(Buffer.byteLength('aaa=', 'base64url'), 2);
// assert.strictEqual(Buffer.byteLength('aaaa==', 'base64url'), 3);
assert.strictEqual(Buffer.byteLength('aaa=', 'base64url'), 2);
assert.strictEqual(Buffer.byteLength('aaaa==', 'base64url'), 3);

assert.strictEqual(Buffer.byteLength('Il était tué'), 14);
assert.strictEqual(Buffer.byteLength('Il était tué', 'utf8'), 14);
Expand Down