bun icon indicating copy to clipboard operation
bun copied to clipboard

Non-ASCII bug on Bun Shell

Open Cow258 opened this issue 8 months ago • 0 comments

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.

  1. Install exiftool
    1. macOS: brew install exiftool
    2. Linux: sudo apt-get install libimage-exiftool-perl
    3. Windows: https://exiftool.org/
  2. Download cat.jpg
  3. 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

image

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

image

What is the expected behavior?

Expected Output

{
  targetRating: "3",
  xmpRating: "3",
}
{
  targetLabel: "檢視",
  xmpLabel: "檢視",
}

Screenshot from Adobe Bridge

image

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 })

Cow258 avatar Jun 28 '24 10:06 Cow258