Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to write \n (newline) to a tag value? #37

Closed
thomax opened this issue Dec 4, 2018 · 6 comments
Closed

How to write \n (newline) to a tag value? #37

thomax opened this issue Dec 4, 2018 · 6 comments

Comments

@thomax
Copy link

thomax commented Dec 4, 2018

exiftool.write('path/to/image.jpg', {'Copyright': 'Agent Smith\n1999'})

Fails with a message that the file named "1999" doesn't exist (Error: File not found - 1999). How can I use newlines in a tag? Any help appreciated :)

@thomax thomax changed the title newline How to write \n (newline) to a tag value? Dec 4, 2018
@mceachen
Copy link
Member

mceachen commented Dec 4, 2018

Thanks for the bug report!

TIL: ExifTool supports "HTML entity escaping". I've implemented this in version 7.4.0 which I just released.

@thomax
Copy link
Author

thomax commented Dec 5, 2018

Thanks to much, that was amazingly quick!

One question, if I may? Please excuse the noob factor, just trying to figure out how this fits together:

Say I want to write a string which includes newline character, would this be the correct code?

const ExifTool = require('exiftool-vendored').ExifTool
const exiftool = new ExifTool({exiftoolArgs: ['-E', '-stay_open', 'True', '-@', '-']}) // using -E in addition to the default args

exiftool.write('path/to/image.jpg', {'Copyright': 'going
going
gone'})
  .then(res => console.log('success', res))
  .catch(err => console.error('failure', err))

When I run the above code, and then read the written tag from the CLI:

> exiftool -Copyright path/to/image.jpg
Copyright                       : going
going
gone
> exiftool -Copyright path/to/image.jpg -b
going
going
gone%

The value of that tag is the literal string I just wrote, without newline characters. What am I missing?

@thomax
Copy link
Author

thomax commented Dec 5, 2018

Just to make sure it works in the CLI, I confirmed that the following works:

> exiftool -E "-Copyright=going
going
gone" path/to/image.jpg
> exiftool -Copyright path/to/image.jpg -b
going
going
gone%

(I've double-checked that I'm running [email protected])

@thomax
Copy link
Author

thomax commented Dec 5, 2018

I also tried this, without any more luck:

exiftool.write('path/to/image.jpg', {'Copyright': 'going
going
gone'}, ['-E'])

@thomax
Copy link
Author

thomax commented Dec 5, 2018

Ah. I've read your source code, followed the callstack and I now understand what's going on.

With v7.4.0, the -E arg is passed by default and therefore all string characters which are HTML-entity-candidates will automatically be encoded. Thus, when I used the literal string 
 in my tag and then called .write it was encoded into &#xa&#59; internally and then back to 
 when exiftool (the cli command) took over.

The solution was simpler than I thought. Just use the string \n instead of 
 :)

@thomax
Copy link
Author

thomax commented Dec 5, 2018

I will now be quite. Thanks for the rubber duck session 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants