1Password / op-js

A JS library powered by the 1Password CLI
https://developer.1password.com/docs/cli
MIT License
91 stars 8 forks source link

Unable to create or edit a field with a period in the title #168

Closed david-driscoll closed 3 months ago

david-driscoll commented 10 months ago

Your environment

op-js version: 0.1.11

CLI version: 2.21.0

OS: Windows / Linux (WSL)

What happened?

It is impossible to to create or edit a field or section with a . in the name.

What did you expect to happen?

I should be able to create a field with a . in the name.

Steps to reproduce

item.edit('my item', [ [ 'package\\.json', 'file', 'myfilepath' ] ]) This will always create a section named package\ with a field of json.

Notes & Logs

It appears to be related to this method:

sanitizeInput = (str: string) => str.replace(/(["$'\\`])/g, "\\$1")

https://github.com/1Password/op-js/blob/382cf11b5261cff0998db793b485ad0163023760/src/cli.ts#L94C1-L95C37

The method will always replace the backslashes in the string and then escape those backslashes, which makes it so that the period can never itself be escaped.

I'm not sure what the best way to modify this is, I would thing something that could do a look ahead to see if the caller has already escaped a special character?

dreusel commented 6 months ago

I am struggling with the same issue. I need to add fields that have periods in their name, which we need to escape to prevent them from being interpreted as sections but the wrapper makes this impossible.