-
Notifications
You must be signed in to change notification settings - Fork 57
Use alternative split char #205
base: master
Are you sure you want to change the base?
Conversation
Good catch but it seems it will make the existed config file no longer works, maybe do a character escape like |
@BLumia not sure. Wouldn't an escaped As for existing config files... you're right. I have added backward compatibility in the latest commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay for me, @justforlxz any suggestions?
@BLumia not sure. Wouldn't an escaped
\@
still count as a@
when splitting? I am afraid it will.
In that case we cannot just simply do a split
:)
As for existing config files... you're right. I have added backward compatibility in the latest commit.
Good, I'll check if |
can be yet another usable character or not, then I think we can merge it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest use :
as the separator if you don't want to use escaped character and do escape/unescape while read/write. Since both @
and |
are valid to use in username. Try sudo useradd 'a|a'
and sudo useradd 'a@a'
and see the result.
Since /etc/passwd
use :
as separator, and sudo useradd 'a:a'
will also give us a useradd: invalid user name 'a:a'
output, I guess it can be safe to use :
as the separator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah really sorry I forget IPv6 address can have :
. Then I guess maybe we cannot continue use a simply split()
.
I guess the best way is continue using this format but only treat last two @
as valid separator or do string escape and unescape manually. What do you think?
I think having a |
We're glad you found the
A escaped string can be A much simpler way to implement (instead of using the escaped/unescaped approach) is just treat last two In // pseudo code, *not* real vala code.
// reverse the original string, split.
server_infos = server_info.reverse().split("@", 3);
// reverse the result list. strings in the list still need to be reverse().
server_infos.reverse();
// reverse the strings inside the list.
server_infos.foreach ((entry) => {
entry.reverse();
}); Or other ways can also works like just simply split with |
Possibly. Or BASE64 encode username/host and then we can use split with the current char ( |
@BLumia i like your suggestion, it is backward compatible and also solves the original problem as well, without users needing to know, that they have to use special characters in that case. I think it's the most intuitve solutation. @ratcashdev BASE64 is an approach, but will not work with old configuration files - you may introduce some patterns so ensure if the file is encoded or not and to do that at the next time you save the file. So the solution from @BLumia seems be an quick win. |
to solve #204