alcjzk / Webserv

0 stars 0 forks source link

Tini: Modify parsing to accept escape character #27

Closed lsileoni closed 8 months ago

lsileoni commented 8 months ago

Essentially, this pull request changes the behavior of how Tini parses configuration files. Tini can now accept \as a special escape char. This was specifically needed because domain names for example couldn't be represented as they had dots in them. To implement this, all I had to essentially change was to make tiniutils::splitaccept a third optional parameter escape, which makes the split implementation skip over it if it happens to match with the delimiter.

Essentially it functions like:

    std::string teststr = ("first.www\.second\.com");
    std::vector<std::string>result = tiniutils::split(teststr, ".", '\\');

    EXPECT(result[0] == "split");
    EXPECT(result[1] == "www.second.com");

Which allows TiniTree to parse hostname urls on the map context switches literally.

So the configuration file can now accept such Host:

[servers.beta.www\.example\.com.routes./source]
...

Some small changes had to also be made on TiniValidator to make it also recognize the escaped chars as valid. In TiniNode, S_ALPHA was changed to S_VALID as this broadened scope allows more than just alphabetical chars in the context switch.

Other changes include introducing namespaces to TiniUtils, primarily to implement testing capability for namespaces and also to not confuse people reading the code as to where for example the split function originates from, as it's used in more places, than just Tini*.cpp. Additionally, the regex in testgen was changed to accomodate for tests to namespaces as well.

image

Tests were implemented specifically for the splitfunction and it appears to behave as expected.

This pull request closes #26