Skip to content

Commit bd8e3e3

Browse files
committed
Fix connection form: use string concat workaround for Perry NaN-boxing bugs
textfieldGetString returns correct values at the native level, but Perry's codegen strips the NaN-box tag when storing in is_string locals. This causes || to treat values as falsy and encodeURIComponent to produce "undefined". Workaround: use `textfieldGetString(field) + ''` to force Perry's string concatenation codegen path, which correctly handles i64 string pointers. Then use .length checks for conditionals. Also adds Edit menu with standard macOS actions (Cmd+A/C/V/X) and Tab navigation between connection form fields. Perry bugs filed: PerryTS/perry#10, #11, #12
1 parent d122e4d commit bd8e3e3

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

src/app.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -717,24 +717,23 @@ function showConnectionForm(): void {
717717
const host = (typeof hostRaw === 'string' && hostRaw.length > 0) ? hostRaw : (formHost || 'localhost');
718718
const portRaw = textfieldGetString(portField);
719719
const port = (typeof portRaw === 'string' && portRaw.length > 0) ? portRaw : (formPort || '27017');
720-
const user = textfieldGetString(userField) || '';
721-
const pass = textfieldGetString(passField) || '';
722-
const rawUri = textfieldGetString(uriField) || '';
723-
724-
// Build URI from fields if no explicit URI provided
725-
let uri = rawUri;
726-
if (!uri) {
727-
// Only include auth if BOTH user and pass are non-empty real strings
728-
let hasAuth = false;
729-
if (user) {
730-
const uTest = encodeURIComponent(user);
731-
if (uTest.indexOf('undef') < 0 && uTest.length > 0) hasAuth = true;
732-
}
733-
if (hasAuth && pass) {
734-
uri = 'mongodb://' + encodeURIComponent(user) + ':' + encodeURIComponent(pass) + '@' + host + ':' + port;
735-
} else {
736-
uri = 'mongodb://' + host + ':' + port;
737-
}
720+
// Build URI using string concatenation (+) which Perry's codegen handles
721+
// correctly for is_string locals. encodeURIComponent and || fail due to
722+
// NaN-boxing being stripped (see PerryTS/perry#10, #12).
723+
// Read user/pass into string variables via + '' (forces string concat path)
724+
const userStr = textfieldGetString(userField) + '';
725+
const passStr = textfieldGetString(passField) + '';
726+
const uriStr = textfieldGetString(uriField) + '';
727+
728+
let uri = '';
729+
if (uriStr.length > 0) {
730+
uri = uriStr;
731+
} else if (userStr.length > 0 && passStr.length > 0) {
732+
// Note: not using encodeURIComponent — it corrupts NaN-boxed strings.
733+
// Users with special chars in user/pass should use the URI field instead.
734+
uri = 'mongodb://' + userStr + ':' + passStr + '@' + host + ':' + port;
735+
} else {
736+
uri = 'mongodb://' + host + ':' + port;
738737
}
739738

740739
// Extract host (without port) from URI for display in connection list
@@ -773,6 +772,8 @@ function showConnectionForm(): void {
773772
formPort = '27017';
774773
formUser = '';
775774
formPass = '';
775+
saveState('_fu', '');
776+
saveState('_fp', '');
776777
formUri = '';
777778
widgetSetHidden(formContainer, 1);
778779
widgetSetHidden(connListContainer, 0);

0 commit comments

Comments
 (0)