SF Unicode cuts open-input-string
Environment/Versions
- GIMP version: 2.99.18, 2.99.16
- Package:
- Operating System: Windows 10, Ubuntu 23.04
Description of the bug
Reproduction
Is the bug reproducible? Always
Reproduction steps:
- Gimp menu "Filters" > "Development" > "Script-Fu" > "Console";
- In the Script-Fu console, copy and paste the following Scheme expression:
(read (open-input-string "'(λ)"))
Expected result:
"'(λ)"
Actual result:
Error: syntax error: expected right paren, found EOF
Click to reproduce the expected result?
The expected result is displayed in Windows 10 stable SF 2.10.36
(read (open-input-string "'(λ)"))
'(λ)
Additional information
The Unicode "λ" character is rendered in Script-Fu Console 2.99.18
However the count of characters could be wrong during the internal copy in the buffer of the input string port, hence the missing right parenthesis:
; Read open-input-string port character by character until nbrChar. End at EOF before the right parenthesis
(define (MissingRightParenthesis nbrChar)
(let loop ((portStr (open-input-string "'(λ)")))
(let loop ((idxCh 0))
(if (< idxCh nbrChar)
(let ((ch (read-char portStr)))
(if (eof-object? ch)
(begin (display "\n0123\nEOF at 0-based index ")(display idxCh))
(begin (display ch) (loop (+ idxCh 1)))
) ) ) )
(close-port portStr) (newline)
) )
Run in the Script-Fu console of Gimp 2.99.18:
(MissingRightParenthesis 4)
'(λ
0123
EOF at 0-based index 3
#t
Positive test
Without Unicode char, there are not any issues:
; OK: Windows 10 Gimp 2.99.18 Script-Fu replacing "λ" with "ascii"
(read (open-input-string "'(ascii)"))
'(ascii)
The issue is located in open-input-string but not open-output-string:
; OK: Win10 SF 2.99.18 replacing open-input-string with open-output-string + get-output-string
(let ((port (open-output-string)))(display "'(λ)" port)(prog1 (get-output-string port)(close-port port)))
"'(λ)"
Even if TS 1.42 renders Unicode char "λ" as "?", it does not eat the closed parenthesis.
C:\Tool\Gimp\scheme\TinyScheme\tinyscheme-1.42\bin>scheme.exe
TinyScheme 1.42
ts> (read (open-input-string "'(λ)"))
'(?)
ts>
Conclusion
This is SF 2.99 open-input-string Unicode count of char regression with regards to 2.10