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

[v20.x] backport libuv wtf-8 decoding fix #51976

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 3 additions & 1 deletion deps/uv/src/win/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ static int32_t fs__decode_wtf8_char(const char** input) {
if ((b4 & 0xC0) != 0x80)
return -1; /* invalid: not a continuation byte */
code_point = (code_point << 6) | (b4 & 0x3F);
if (b1 <= 0xF4)
if (b1 <= 0xF4) {
code_point &= 0x1FFFFF;
if (code_point <= 0x10FFFF)
return code_point; /* four-byte character */
}

/* code point too large */
return -1;
Expand Down
31 changes: 31 additions & 0 deletions test/parallel/test-fs-operations-with-surrogate-pairs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

require('../common');
const fs = require('node:fs');
const path = require('node:path');
const assert = require('node:assert');
const { describe, it } = require('node:test');
const tmpdir = require('../common/tmpdir');

tmpdir.refresh();

describe('File operations with filenames containing surrogate pairs', () => {
it('should write, read, and delete a file with surrogate pairs in the filename', () => {
// Create a temporary directory
const tempdir = fs.mkdtempSync(tmpdir.resolve('emoji-fruit-🍇 🍈 🍉 🍊 🍋'));
assert.strictEqual(fs.existsSync(tempdir), true);

const filename = '🚀🔥🛸.txt';
const content = 'Test content';

// Write content to a file
fs.writeFileSync(path.join(tempdir, filename), content);

// Read content from the file
const readContent = fs.readFileSync(path.join(tempdir, filename), 'utf8');

// Check if the content matches
assert.strictEqual(readContent, content);

});
});
Loading