cpe icon indicating copy to clipboard operation
cpe copied to clipboard

Question: Unescaped component values

Open jimcarreer opened this issue 4 years ago • 0 comments

So I noticed something interesting with this library:

import cpe
raw_23_string = '''cpe:2.3:a:\!\(\/:*:*:*:*:*:*:*:*:*'''
parsed_23 = cpe.CPE(raw_23_string)
print(parsed_23.as_fs())
print(parsed_23.get_vendor())
parsed_23_uri = cpe.CPE(parsed_23.as_uri_2_3())
print(parsed_23_uri.as_fs())
print(parsed_23_uri.get_vendor())

Which outputs:

cpe:2.3:a:\!\(\/:*:*:*:*:*:*:*:*:*
['\\!\\(\\/']
cpe:2.3:a:\!\(\/:*:*:*:*:*:*:*:*:*
['%21%28%2f']

While I think I understand the rationale of preserving the original components value (be it URI encoded, or special character escaped for the formatted string), it seems like a problem with the library that I can't just get the unescaped/unencoded value at all. That is to say, I wish there were some way to just get vendor in my example as:

['!(/']

Why? Because if you're storing these in a database to search or display to users in a nicer user interface, if the component contains special characters, invariably you would want to present the string, or have the user search on it, it the most friendly way to them, in this case unescaped / encoded. Encoding / escaping should be a concern at the time a specific format is asked for.

I'm willing to contribute a PR potentially to implement this but was wondering if I could get pointed in the right direction for it.

jimcarreer avatar Feb 14 '21 12:02 jimcarreer