Support escaping of pipe characters within multi-valued slots.#17
Open
Support escaping of pipe characters within multi-valued slots.#17
Conversation
Currently, because the pipe character (`|`) is used to separate the different values of a multi-valued slot in the TSV serialisation, said values cannot contain a pipe character themselves. There is no real reason for the serialisation format to mandate such a restriction. This commit implements a mechanism allowing to encode pipe characters in the values of a multi-valued slot. Briefly, and only in the context of a multi-valued slot in TSV format: * a `\|` sequence (backslash + pipe) is interpreted as a `|` character that is part of the current value, NOT as the value separator; * a `\\` sequence (double backslash) is interpreted as a `\` character that is part of the current value; * any other occurrence of a backslash character is treated as a normal character that is part of the current value. When writing a multi-valued slot in TSV, the writer must: * escape any '|' character that is part of the value; * escape a '\' character that is part of the value iff (1) the character is followed by another backslash or a pipe, or (2) the character would be followed by the pipe used to separate values (which would happen if the backslash is the last character of any of the values in the slot except the last one). This commit also fixes a (slightly) unrelated bug in the way multi-valued slots are quoted: if any of the values of a multi-valued slot needs quoting, then it is the entire slot that must be quoted, NOT the individual value.
When reading a set in SSSOM 1.0 compliance mode, we should not try to interpret a `\|` sequence as a literal `|` character, since the escaping mechanism was not described in version 1.0 of the spec.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, because the pipe character (
|) is used to separate the different values of a multi-valued slot in the TSV serialisation, said values cannot contain a pipe character themselves.There is no real reason for the serialisation format to mandate such a restriction. This PR implements a mechanism allowing to encode pipe characters in the values of a multi-valued slot.
Briefly, and only in the context of a multi-valued slot in TSV format:
\|sequence (backslash + pipe) is interpreted as a|character that is part of the current value, NOT as the value separator;\\sequence (double backslash) is interpreted as a\character that is part of the current value;When writing a multi-valued slot in TSV, the writer must:
|character that is part of the value;\character that is part of the value iff (1) the character is followed by another backslash or a pipe, or (2) the character would be followed by the pipe used to separate values (which would happen if the backslash is the last character of any of the values in the slot except the last one).This PR also fixes a (slightly) unrelated bug in the way multi-valued slots are quoted: if any of the values of a multi-valued slot needs quoting, then it is the entire slot that must be quoted, NOT the individual value.