ini icon indicating copy to clipboard operation
ini copied to clipboard

[BUG] Problem with # in value ini

Open kchojnacki opened this issue 3 years ago • 2 comments

What / Why

Problem with # in value ini

n/a

When

string in ini have #

  • n/a

Where

`function unsafe (val, doUnesc) { val = (val || '').trim() if (isQuoted(val)) { // remove the single quotes before calling JSON.parse if (val.charAt(0) === "'") val = val.substr(1, val.length - 2)

try {
  val = JSON.parse(val)
} catch (_) {}

} else { // walk the val to find the first not-escaped ; character var esc = false var unesc = '' for (var i = 0, l = val.length; i < l; i++) { var c = val.charAt(i) if (esc) { if ('\;#'.indexOf(c) !== -1) unesc += c else unesc += '\' + c

    esc = false
  } else if (';#'.indexOf(c) !== -1)
    break
  else if (c === '\\')
    esc = true
  else
    unesc += c
}
if (esc)
  unesc += '\\'

return unesc.trim()

} return val }`

  • n/a

How

Current Behavior

  • n/a

Steps to Reproduce

  • n/a

Expected Behavior

You need to delete # in :

} else if (';#'.indexOf(c) !== -1)

and

if ('\;#'.indexOf(c) !== -1)

to:

} else if (';'.indexOf(c) !== -1)

and

if ('\;'.indexOf(c) !== -1)

  • n/a

Who

  • n/a

References

  • n/a

kchojnacki avatar Dec 11 '20 13:12 kchojnacki

i am having the same

ghost avatar Mar 18 '21 17:03 ghost

You can try my fork, ini-win, which aims to be more compatible with the way Windows handles ini files. Windows only supports whole line comments, and so does my fork, so it fixes this issue.

m417z avatar Mar 17 '22 21:03 m417z

This would constitute a breaking change for folks who are relying on the behavior that an unquoted string has and is unlikely to change. If you have values with special characters please escape them or quote them.

> ini.decode('key=value\\#value')
[Object: null prototype] { key: 'value#value' }
> ini.decode('key="value#value"')
[Object: null prototype] { key: 'value#value' }
> ini.encode({ key: 'value#value' })
'key=value\\#value\n'

wraithgar avatar Apr 13 '23 17:04 wraithgar