Skip to content

Commit 6c3da6d

Browse files
authored
fix(fs): use correct line detection for encodings in readTextFileLines (#3273)
Co-authored-by: OkaYu <aiueo13>
1 parent e97a4de commit 6c3da6d

3 files changed

Lines changed: 154 additions & 32 deletions

File tree

plugins/fs/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/fs/guest-js/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -812,10 +812,15 @@ async function readTextFileLines(
812812
rid: null as number | null,
813813

814814
async next(): Promise<IteratorResult<string>> {
815+
const decoder = new TextDecoder(options?.encoding ?? 'utf-8')
816+
815817
if (this.rid === null) {
818+
// Use the normalized encoding label for options.
819+
const encoding = decoder.encoding
820+
816821
this.rid = await invoke<number>('plugin:fs|read_text_file_lines', {
817822
path: pathStr,
818-
options
823+
options: options != null ? { ...options, encoding } : undefined
819824
})
820825
}
821826

@@ -840,9 +845,7 @@ async function readTextFileLines(
840845
return { value: null, done }
841846
}
842847

843-
const line = new TextDecoder(options?.encoding ?? 'utf-8').decode(
844-
bytes.slice(0, bytes.byteLength - 1)
845-
)
848+
const line = decoder.decode(bytes.slice(0, bytes.byteLength - 1))
846849

847850
return {
848851
value: line,

0 commit comments

Comments
 (0)