bun
bun copied to clipboard
Non-ASCII bug on Bun Shell
What version of Bun is running?
1.1.17+bb66bba1b
What platform is your computer?
Darwin 23.5.0 arm64 arm
What steps can reproduce the bug?
How to reproduce
To reproduce this issue with this source code.
- Install
exiftool
- macOS:
brew install exiftool
- Linux:
sudo apt-get install libimage-exiftool-perl
- Windows: https://exiftool.org/
- macOS:
- Download cat.jpg
-
bun ./index.js
Source code 1
import { $ } from 'bun'
const targetRating = '3'
const targetLabel = '檢視'
const targetPath = 'cat.jpg'
// Reset rating and label
await $`exiftool -xmp:Rating= -xmp:Label= -overwrite_original '${targetPath}'`.quiet()
// Write rating and label (A problem occurs in this line!!!)
await $`exiftool -xmp:Rating=${targetRating} -xmp:Label='${targetLabel}' -overwrite_original '${targetPath}'`
// Read rating and label
const output = await $`exiftool -xmp:Rating -xmp:Label '${targetPath}'`.quiet()
const { xmpRating, xmpLabel } = output.text()
.split('\n')
.filter(line => !!line.trim())
.map(line => line.split(':').map(str => str.trim()))
.reduce((acc, [key, value]) => {
acc[`xmp${key}`] = value
return acc
}, {})
console.log({ targetRating, xmpRating })
console.log({ targetLabel, xmpLabel })
Output 1
> bun ./issue.js
Warning: Not a floating point number for XMP-xmp:Rating
1 image files updated
{
targetRating: "3",
xmpRating: undefined,
}
{
targetLabel: "檢視",
xmpLabel: "檢視",
}
Screenshot from Adobe Bridge
Source code 2 (Modified to static string)
await $`exiftool -xmp:Rating=3 -xmp:Label='檢視' -overwrite_original 'cat.jpg'`
Output 2
> bun ./issue.js
1 image files updated
{
targetRating: "3",
xmpRating: "3",
}
{
targetLabel: "檢視",
xmpLabel: "\\u6AA2\\u8996",
}
Screenshot from Adobe Bridge
What is the expected behavior?
Expected Output
{
targetRating: "3",
xmpRating: "3",
}
{
targetLabel: "檢視",
xmpLabel: "檢視",
}
Screenshot from Adobe Bridge
What do you see instead?
No response
Additional information
You can get the expected output from following code.
import { exec } from 'child_process'
import path from 'path'
const targetRating = '3'
const targetLabel = '檢視'
const targetPath = 'cat.jpg'
function Exec(cmd, cwd) {
cwd = cwd || path.resolve('./')
return new Promise((resolve, reject) => {
console.log(`> \x1b[2m${cmd}\x1b[0m`)
exec(cmd, { cwd }, (error, stdout, stderr) => {
if (error) { console.error(`error: ${error}`); reject(error); return }
if (stdout) console.log(stdout)
if (stderr) console.log(stderr)
resolve(stdout)
})
})
}
await Exec(`exiftool -xmp:Rating=${targetRating} -xmp:Label='${targetLabel}' -overwrite_original '${targetPath}'`)
const { xmpRating, xmpLabel } = (await Exec(`exiftool -xmp:Rating -xmp:Label '${targetPath}'`))
.split('\n')
.filter(line => !!line.trim())
.map(line => line.split(':').map(str => str.trim()))
.reduce((acc, [key, value]) => {
acc[`xmp${key}`] = value
return acc
}, {})
console.log({ targetRating, xmpRating })
console.log({ targetLabel, xmpLabel })