Opened 5 years ago

Closed 4 years ago

#1325 closed defect (fixed)

SAM - Parsing of Properties

Reported by: ExtraBattery Owned by: mkvore
Priority: minor Milestone: 0.9.24
Component: apps/SAM Version: 0.9.13
Keywords: Cc:
Parent Tickets: #1488, #1574 Sensitive: no

Description

There was a similar problem reported in #950.

Taking a look (no testing) at the routine parseParams() in "SAMUtils.java": It seems to allow for the key to be an empty string. So this would be treated as legal:

=value =value2 =value3

There is also a mechanism that handles quoted values. It seems not to take into account that the StringTokenizer? treats multiple subsequent delimiters as one. So this:

PASSWORD="Jane   Doe" (imagine three *normal* (0x20) spaces between Jane and Doe, but Trac seems to remove them to make it harder for me to make the point, so I used 0xA0 instead)

seems to be treated as:

PASSWORD="Jane Doe"

Since there is no escape sequence, it is impossible to use a string as a value that contains a quote char and a space char later. So this:

PASSWORD="Jane " Doe"

would be rejected as illegal.

Subtickets

Change History (6)

comment:1 Changed 5 years ago by zzz

While there is some quote handling in the code, I can't find anything in the website docs about it. I wonder if anybody uses quotes.

We have a few methods elsewhere that parse foo=bar lines, all a little different. I wonder if one of them would work. I was also thinking about consolidating them into a util class someday…

parseArgs() methods are in EepGet?, LoadClientAppsJob?, and NewsFetcher?. I2PTunnelHTTPClientBase uses the one in EepGet?. I think that's all of them.

Maybe they could all be combined, maybe not.

comment:2 Changed 5 years ago by zzz

The empty key check is in 0.9.13-10. Spacing issue is not yet addressed.

comment:3 Changed 5 years ago by ExtraBattery

It would be good to handle quoted text like in C-style programming languages, so that you can put something in quotes, while the outer quotes themselves are not treated as part of the quoted string. If you need a quote char in the actual string, you can use an escape sequence for that.

SAM (at the moment) doesn't remove the outer quotes from a quoted text, which is often problematic. And as mentioned in the OP, there is no escape sequence.

One possible usage example are the nicknames of I2P tunnels. You cannot use a text like "Shared Clients" through SAM, as you can't use a space char without using quotes, and if you use quotes, they become a part of the nickname.

As the current handling of quotes is somewhat tricky (and not documented), it is probably not really used by any application. So changes shouldn't break anything. Switching to C-style string handling would be backward compatible to some degree with SAM's current way of handling quoted text.

Combining the string parsing into a central utility class sound like a good idea. Flags could be used for controlling different modes of parsing, where necessary.

Version 0, edited 5 years ago by ExtraBattery (next)

comment:4 Changed 5 years ago by zzz

Parent Tickets: 950

comment:5 Changed 5 years ago by zzz

Parent Tickets: 1574

comment:6 Changed 4 years ago by zzz

Milestone: 0.9.24
Parent Tickets: 15741488, 1574
Resolution: fixed
Status: newclosed

parser rewritten in 99478af9bea7951220238bc86b25d5af44d271ec to be 0.9.23-5
backslash escapes in 99478af9bea7951220238bc86b25d5af44d271ec to be 0.9.23-5
see #1488 for more to do including docs and UTF-8

Note: See TracTickets for help on using tickets.