The best way to control Claude Code, Codex and more from any computer or phone
fix(ssh): count bytes for Include question-mark wildcards (#37840)
Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Simone committed
Nov 17, 2026 at 02:57 UTC
b50e98e71cb2bf4eef71b02a4440253cbde2102f
2 files changed
+23
-3
packages/ssh/src/config.test.ts
+14
-1
@@ -90,7 +90,7 @@ describe("ssh config", () => {
90
yield* fs.makeDirectory(path.join(sshDir, "single.d"));
91
yield* fs.writeFileString(
92
path.join(sshDir, "config"),
93
- "Include config.d/*\nInclude config.d/.literal.conf\nInclude config.d/.enabled-*.conf\nInclude explicit-directory\nInclude single.d/team?one.conf\nHost real\n HostName real.example.com\n",
93
+ "Include config.d/*\nInclude config.d/.literal.conf\nInclude config.d/.enabled-*.conf\nInclude explicit-directory\nInclude single.d/team?one.conf\nInclude single.d/exact??.conf\nHost real\n HostName real.example.com\nHost svc?x\n HostName wrong.example.com\nHost svc\u2028x\n HostName correct.example.com\n",
94
);
95
for (const [index, separator] of ["\u2028", "\u2029"].entries()) {
96
yield* fs.writeFileString(
@@ -103,6 +103,16 @@ describe("ssh config", () => {
103
path.join(sshDir, "single.d", "team\u2028one.conf"),
104
"Host single-byte\n HostName single-byte.example.com\n",
105
);
106
+ for (const [file, alias] of [
107
+ ["teamxone.conf", "single-ascii"],
108
+ ["teamøone.conf", "single-unicode"],
109
+ ["exactø.conf", "double-byte"],
110
+ ] as const) {
111
+ yield* fs.writeFileString(
112
+ path.join(sshDir, "single.d", file),
113
+ `Host ${alias}\n HostName ${alias}.example.com\n`,
114
+ );
115
+ }
116
yield* fs.writeFileString(
117
path.join(sshDir, "config.d", "team.conf"),
118
"Host team\n HostName team.example.com\n",
@@ -128,10 +138,13 @@ describe("ssh config", () => {
138
assert.deepEqual(
139
hosts.map((host) => [host.alias, host.hostname, host.source]),
140
[
141
+ ["double-byte", "double-byte.example.com", "ssh-config"],
142
["enabled", "enabled.example.com", "ssh-config"],
143
["known.example.com", "known.example.com", "known-hosts"],
144
["literal", "literal.example.com", "ssh-config"],
145
["real", "real.example.com", "ssh-config"],
146
+ ["single-ascii", "single-ascii.example.com", "ssh-config"],
147
+ ["svc\u2028x", "correct.example.com", "ssh-config"],
148
["team", "team.example.com", "ssh-config"],
149
["unicode-0", "unicode-0.example.com", "ssh-config"],
150
["unicode-1", "unicode-1.example.com", "ssh-config"],
packages/ssh/src/config.ts
+9
-2
@@ -90,6 +90,13 @@ function escapeRegex(value: string): string {
90
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
91
}
92
93
+const utf8 = new TextEncoder();
94
+
95
+// OpenSSH's glob matches UTF-8 bytes, so `?` consumes one byte of a filename.
96
+function globBytes(value: string): string {
97
+ return Array.from(utf8.encode(value), (byte) => String.fromCharCode(byte)).join("");
98
+}
99
+
100
function globToRegExp(pattern: string): RegExp {
101
return new RegExp(
102
`^${escapeRegex(pattern).replace(/\\\*/gu, "[^]*").replace(/\\\?/gu, ".")}$`,
@@ -119,7 +126,7 @@ const expandGlob = Effect.fnUntraced(function* (
126
const directoryIsGlob = hasGlobWildcard(directoryPattern);
127
const directories = directoryIsGlob ? yield* expandGlob(directoryPattern) : [directoryPattern];
128
122
- const matcher = globToRegExp(basePattern);
129
+ const matcher = globToRegExp(globBytes(basePattern));
130
const matchedPaths: string[] = [];
131
for (const directory of directories) {
132
if (!(yield* fs.exists(directory))) continue;
@@ -130,7 +137,7 @@ const expandGlob = Effect.fnUntraced(function* (
137
: yield* fs.readDirectory(directory);
138
for (const entry of entries) {
139
if (entry.startsWith(".") && !basePattern.startsWith(".")) continue;
133
- if (!matcher.test(entry)) {
140
+ if (!matcher.test(globBytes(entry))) {
141
continue;
142
}
143
const entryPath = path.join(directory, entry);