diff --git a/crates/engine/src/tests/script_io.rs b/crates/engine/src/tests/script_io.rs index 25ccb3bcfb..5ebebb783b 100644 --- a/crates/engine/src/tests/script_io.rs +++ b/crates/engine/src/tests/script_io.rs @@ -125,6 +125,22 @@ fn file_names_are_uri_encoded_and_current_relative() { let _ = std::fs::remove_dir_all(base); } +/// `localizedName` of a file and a folder is the name they show, decoded, as `displayName` is, +/// not the encoded `name`. +#[test] +fn file_and_folder_give_their_localized_name() { + let base = folder("localized"); + let log = logged( + &base, + "var f = new File('caf%C3%A9 x.txt'), d = new Folder('n%C3%A9w');\n\ + f.localizedName = 'other';\n\ + vc.log([f.localizedName === f.displayName, f.localizedName === f.name, d.localizedName === d.displayName,\n\ + d.localizedName === d.name, f.localizedName, 'localizedName' in Folder.prototype]);", + ); + assert_eq!(log, json!([[true, false, true, false, "caf\u{e9} x.txt", true]])); + let _ = std::fs::remove_dir_all(base); +} + #[test] fn script_file_without_scope_cannot_probe_home() { let base = folder("home"); diff --git a/crates/engine/tests/it/script_host_vs_scriptcheck.rs b/crates/engine/tests/it/script_host_vs_scriptcheck.rs index 52aa59e27d..60239864d7 100644 --- a/crates/engine/tests/it/script_host_vs_scriptcheck.rs +++ b/crates/engine/tests/it/script_host_vs_scriptcheck.rs @@ -59,7 +59,7 @@ const INSIDE: &[(&str, &str)] = &[ ( "File.prototype.", "absoluteURI alias changePath close constructor created creator displayName encoding encoding= eof error error= \ - exists fsName fullName getRelativeURI hidden length lineFeed lineFeed= modified name openDlg parent path read \ + exists fsName fullName getRelativeURI hidden length lineFeed lineFeed= localizedName modified name openDlg parent path read \ readch readln readonly relativeURI resolve saveDlg seek tell toString type", ), ( @@ -70,7 +70,7 @@ const INSIDE: &[(&str, &str)] = &[ ( "Folder.prototype.", "absoluteURI alias changePath constructor created displayName error error= exists fsName fullName getFiles \ - getRelativeURI modified name parent path relativeURI resolve selectDlg toString", + getRelativeURI localizedName modified name parent path relativeURI resolve selectDlg toString", ), ]; diff --git a/crates/js/src/file_classes.rs b/crates/js/src/file_classes.rs index 30de04cf12..f7e85046a0 100644 --- a/crates/js/src/file_classes.rs +++ b/crates/js/src/file_classes.rs @@ -314,6 +314,12 @@ fn display_name(i: &mut Interp, this: Value, _: &[Value], _: bool) -> JsResult JsResult { + parsed(i, &this, "localizedName", "display") +} + fn path(i: &mut Interp, this: Value, _: &[Value], _: bool) -> JsResult { parsed(i, &this, "path", "path") } @@ -1029,6 +1035,7 @@ fn common(i: &mut Interp, ctor: ObjId, proto: ObjId) -> JsResult<()> { accessor(i, proto, "relativeURI", relative_uri, None)?; accessor(i, proto, "name", name, None)?; accessor(i, proto, "displayName", display_name, None)?; + accessor(i, proto, "localizedName", localized_name, None)?; accessor(i, proto, "path", path, None)?; accessor(i, proto, "parent", parent, None)?; accessor(i, proto, "exists", exists, None)?; diff --git a/docs/mcp.md b/docs/mcp.md index bc3818c87a..87301d0bf5 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2948,10 +2948,11 @@ script reads files with them: `%xx` escapes are read as UTF-8, and on Windows `/` and `\` both separate names and `/c/` names drive C. `File(path)` without `new` gives a `Folder` for an existing folder, and `Folder(path)` gives a `File` for an existing file. Two objects for the same path are different objects. -- `name`, `displayName`, `fsName`, `absoluteURI`, `fullName`, `relativeURI`, `path`, `parent` and `toString()` come - from the path. `exists`, `length`, `created`, `modified`, `hidden`, `readonly` and `alias` read the file system. - `exists` is true for a `File` only when the path names something other than a folder, and for a `Folder` only - when it names a folder. +- `name`, `displayName`, `localizedName`, `fsName`, `absoluteURI`, `fullName`, `relativeURI`, `path`, `parent` and + `toString()` come from the path. `localizedName` gives the same decoded name as `displayName`: VectorCraft does not + look up a name the system shows in another language. `exists`, `length`, `created`, `modified`, `hidden`, + `readonly` and `alias` read the file system. `exists` is true for a `File` only when the path names something + other than a folder, and for a `Folder` only when it names a folder. `File.encode`, `File.decode` and `File.isEncodingAvailable` (and the same on `Folder`), `File.fs`, and the folders `Folder.temp`, `Folder.desktop`, `Folder.myDocuments`, `Folder.userData` and the others are there too. - `open('r')` opens a file to read, and `read([chars])`, `readln()`, `readch()`, `seek(pos[, mode])`, `tell()`, `eof` diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 8b4a1045eb..ad8f786bad 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1046,7 +1046,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Scripts: `$.fileName` is a read-only name of the script file in use ([the help page](https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/)). VectorCraft's own rules: it names the file of the code that reads it, so a function a file included with `#include` or run with `$.evalFile` defined, or one an earlier run of a named engine kept, gives its own file and not the calling file; code from a script given as `source`, and kept code whose place the engine dropped, gives an empty name, and code that `eval` or `Function` compiled gives the file being run. `crates/engine/src/tests/script_include.rs`, `crates/engine/src/tests/script_engines.rs`. - Scripts: a runtime error is shown at the line that was running ([the help page](https://extendscript.docsforadobe.dev/extendscript-toolkit/debugging-in-the-toolkit/)). VectorCraft's own rules: an error in code an earlier run of a named engine compiled, such as a function it defined, is reported at that code's file, line and column (the earlier run's script, a file it included or a file its `$.evalFile` ran), while the report and its console line keep the calling run's name; a script given as text is named by its run's name, and each engine keeps these places for 8 MiB of source maps, the oldest going first. An error in code whose place is gone, or in code that `eval` or `Function` compiled, is reported without a line and column, and the code still runs. `crates/engine/src/tests/script_engines.rs`. - Scripts: `$.line` is the line of the running script, counting from 1, and `$.stack` is the current stack trace ([the help page](https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/)). VectorCraft's own rules: both count lines in the file the code is in (the script, a file it included, a file `$.evalFile` ran, or the file of an earlier run of the named engine), and `$.stack` starts with a line holding the run's name in square brackets, such as `[main.jsx]`, then writes each frame as `name@file:line`, outermost first; code that `eval` or `Function` compiled keeps its own line in `[eval]`, and code whose place the engine no longer keeps is at line 0 of `[unknown]`. `crates/engine/src/tests/script_include.rs`, `crates/engine/src/tests/script_engines.rs`, `crates/engine/src/tests/script_dollar.rs`, `crates/js/src/extension_tests.rs`. - - Scripts: `File` and `Folder` ([File object](https://extendscript.docsforadobe.dev/file-system-access/file-object/), [Folder object](https://extendscript.docsforadobe.dev/file-system-access/folder-object/)) name files and folders by platform or URI path, with `name`, `fsName`, `absoluteURI`, `relativeURI`, `parent`, `Folder.current` and `encode`/`decode`, and read them: `exists`, `length`, the dates, `getFiles` with a mask or a function, and `open('r')` with `read`, `readln`, `readch`, `seek`, `tell` and `close`, decoding by byte order mark, `encoding`, UTF-8 or CP1252. VectorCraft's own rules: a script reads only in its own folder and below (and inside the automation read roots when they are set); any other path and a network or device path are refused before anything is looked up, and a link that leads out is refused as well (`false` or `null`, with `error` set); a file is read whole up to 8 MiB and a run reads up to 32 MiB; `execute` is not available. `crates/engine/src/tests/script_io.rs`. + - Scripts: `File` and `Folder` ([File object](https://extendscript.docsforadobe.dev/file-system-access/file-object/), [Folder object](https://extendscript.docsforadobe.dev/file-system-access/folder-object/)) name files and folders by platform or URI path, with `name`, `fsName`, `absoluteURI`, `relativeURI`, `parent`, `localizedName`, `Folder.current` and `encode`/`decode`, and read them: `exists`, `length`, the dates, `getFiles` with a mask or a function, and `open('r')` with `read`, `readln`, `readch`, `seek`, `tell` and `close`, decoding by byte order mark, `encoding`, UTF-8 or CP1252. VectorCraft's own rules: `localizedName` gives the same decoded name as `displayName`, without looking up a name the system shows in another language; a script reads only in its own folder and below (and inside the automation read roots when they are set); any other path and a network or device path are refused before anything is looked up, and a link that leads out is refused as well (`false` or `null`, with `error` set); a file is read whole up to 8 MiB and a run reads up to 32 MiB; `execute` is not available. `crates/engine/src/tests/script_io.rs`. - Scripts: `File` and `Folder` write ([File object](https://extendscript.docsforadobe.dev/file-system-access/file-object/), [Folder object](https://extendscript.docsforadobe.dev/file-system-access/folder-object/)): `open('w')`, `open('e')` and `open('a')` with `write` and `writeln` by `lineFeed`, `copy`, `remove` (a folder only when empty), `rename`, `folder.create()`, the `length` and `readonly` setters, and `File.openDialog`, `File.saveDialog`, `Folder.selectDialog`, `openDlg`, `saveDlg` and `selectDlg`, with a `filter` of file types or a filter function and `multiSelect`. VectorCraft's own rules: a script writes only in `Folder.temp` (one for the run, deleted when it ends), its own `Folder.userData` next to the settings, and what a person allowed it in a file dialog, once or always; Always keeps the grant for that script file with that text by its SHA-256 and for the sources the run evaluated (`$.evalFile`, `eval`, `Function`), so a run that evaluates other code, or whose named engine holds other code, loses it first; `script.grants` lists the grants and `script.grants.revoke` removes them; the settings folder is kept out of every grant; the commands a script runs with `vc.run` read and write only in the same places and the open documents' own files, and read the files linked as the next line says; a run with nobody to ask gets `null` from the dialogs; a file is written at close or when the run ends, 8 MiB a file and 32 MiB a run, and named in `written`, also after a run that failed. `crates/engine/src/tests/script_io.rs`. - Scripts: an export, save, print or package that a script runs with `vc.run` includes the linked images and placed files of the documents open when the run began, also when those files are outside the script's own places. VectorCraft's own rules: the commands read those files as the links led at the run's first `vc.run` and as the person last opened or saved each document; a link does not let them write the file it names, and they write a linked file only where the previous line lets them write (the script's own write places and the open documents' own files); a path that leads to another file since, a link or data set value a script's command adds or changes, in that run or an earlier one, and a document a script's command opens give it no further file to read, and a document a script's command opened gives the commands no access to its own file until the person saves it; a linked file in the folder that holds the settings is not read unless it lies in one of the script's own places inside that folder, and the automation read roots still apply. `crates/engine/src/tests/script_run.rs`, `file_access::tests` in `vectorcraft-engine`. - Scripts: the `hidden` setter and `createAlias(target)` ([File object](https://extendscript.docsforadobe.dev/file-system-access/file-object/)), with setting `hidden`, `rename` and `remove` acting on an alias itself ([Using File and Folder objects](https://extendscript.docsforadobe.dev/file-system-access/using-file-and-folder-objects/)). VectorCraft's own rules: on Unix a name that starts with a dot is hidden, so setting `hidden` renames the file with one dot added or its leading dots taken off, and both names must be places the script may write; `createAlias` makes a symbolic link to the real path of a file the script may read, in a place it may write where nothing is, a link that leads nowhere included; a link is checked again each time it is used; on Windows both set `error` and change nothing. `crates/engine/src/tests/script_io.rs`.