diff options
author | socialgraph <socialgraph@yandex-team.com> | 2022-09-08 14:28:30 +0300 |
---|---|---|
committer | socialgraph <socialgraph@yandex-team.com> | 2022-09-08 14:28:30 +0300 |
commit | dfe3fdb76414445f7674788b36e925d49280e9f1 (patch) | |
tree | 844d2f9dd199440f700d7ef28e1d208b67f827b7 /library/cpp/uri | |
parent | 1e2781d41b8073e19248305f6d51888dfa6d469d (diff) | |
download | ydb-dfe3fdb76414445f7674788b36e925d49280e9f1.tar.gz |
use hash bang flag
use hash bang flag
Diffstat (limited to 'library/cpp/uri')
-rw-r--r-- | library/cpp/uri/assign.cpp | 2 | ||||
-rw-r--r-- | library/cpp/uri/common.cpp | 2 | ||||
-rw-r--r-- | library/cpp/uri/common.h | 2 | ||||
-rw-r--r-- | library/cpp/uri/encode.cpp | 22 | ||||
-rw-r--r-- | library/cpp/uri/http_url.h | 4 | ||||
-rw-r--r-- | library/cpp/uri/parse.cpp | 5 | ||||
-rw-r--r-- | library/cpp/uri/uri.cpp | 14 | ||||
-rw-r--r-- | library/cpp/uri/uri.h | 2 |
8 files changed, 36 insertions, 17 deletions
diff --git a/library/cpp/uri/assign.cpp b/library/cpp/uri/assign.cpp index 9205fc5817..4bb20ca656 100644 --- a/library/cpp/uri/assign.cpp +++ b/library/cpp/uri/assign.cpp @@ -155,6 +155,7 @@ namespace NUri { if (fragment.IsSet()) { HashBang = fragment.Get(); if (!HashBang.empty() && '!' == HashBang[0]) { + HashBang.Skip(1); // remove ! return true; } } @@ -182,7 +183,6 @@ namespace NUri { } } else if (0 != (parser.Flags & TFeature::FeatureHashBangToEscapedFragment)) { if (ParseHashBangFromFragment(parser)) { - HashBang.Skip(1); // remove ! FromFragmentToQuery = true; buflen += ESCAPED_FRAGMENT.length(); buflen += 2 * HashBang.length(); // encode diff --git a/library/cpp/uri/common.cpp b/library/cpp/uri/common.cpp index 5bcb2fc38b..7225e22dfd 100644 --- a/library/cpp/uri/common.cpp +++ b/library/cpp/uri/common.cpp @@ -100,6 +100,8 @@ namespace NUri { return "query"; case TField::FieldFrag: return "fragment"; + case TField::FieldHashBang: + return "hashbang"; default: return "Field[Unknown]"; } diff --git a/library/cpp/uri/common.h b/library/cpp/uri/common.h index 5dbae78226..f990809659 100644 --- a/library/cpp/uri/common.h +++ b/library/cpp/uri/common.h @@ -58,6 +58,7 @@ namespace NUri { FIELD_FLAG(Path), FIELD_FLAG(Query), FIELD_FLAG(Frag), + FIELD_FLAG(HashBang), FIELD_FLAG(UrlMAX), FIELD_FLAG(HostAscii), FIELD_FLAG(AllMAX), @@ -67,6 +68,7 @@ namespace NUri { FlagFragment = FlagFrag, FlagAction = FlagScheme | FlagHostPort | FlagPath, FlagNoFrag = FlagAction | FlagQuery, + FlagFragmentLess = FlagAction | FlagQuery | FlagHashBang, FlagUrlFields = FlagUrlMAX - 1, FlagAll = FlagUrlFields, // obsolete, for backwards compatibility FlagAllFields = FlagAllMAX - 1 diff --git a/library/cpp/uri/encode.cpp b/library/cpp/uri/encode.cpp index 584fb1bac9..27ed750324 100644 --- a/library/cpp/uri/encode.cpp +++ b/library/cpp/uri/encode.cpp @@ -14,14 +14,14 @@ namespace NUri { // remove '#' which can't ever be decoded // don't mark anything allowed for pass (pass is completely encoded) -// safe in path, qry, frag +// safe in path, qry, frag, hashbang #define GENDELIMS1 ":@" -// allowed in qry, frag +// allowed in qry, frag, hashbang #define GENDELIMS2 "/?" // qry-unsafe chars #define SUBDELIMS1 "&+=;" -// rest allowed in qry, frag +// rest allowed in qry, frag, hashbang #define SUBDELIMS2 "!$'()*," const TEncoder::TGrammar& TEncoder::Grammar() { @@ -44,11 +44,11 @@ namespace NUri { // now field-specific subsets of reserved characters (gen-delims + sub-delims) const ui64 featSafe = TFeature::FeatureDecodeFieldAllowed; - Add(GENDELIMS1, 0, featSafe, TField::FlagPath | TField::FlagQuery | TField::FlagFrag); - Add(GENDELIMS2, 0, featSafe, TField::FlagQuery | TField::FlagFrag); + Add(GENDELIMS1, 0, featSafe, TField::FlagPath | TField::FlagQuery | TField::FlagFrag | TField::FlagHashBang); + Add(GENDELIMS2, 0, featSafe, TField::FlagQuery | TField::FlagFrag | TField::FlagHashBang); Add(SUBDELIMS1, 0, featSafe, TField::FlagUser); - Add(SUBDELIMS2, 0, featSafe, TField::FlagUser | TField::FlagQuery | TField::FlagFrag); + Add(SUBDELIMS2, 0, featSafe, TField::FlagUser | TField::FlagQuery | TField::FlagFrag | TField::FlagHashBang); // control chars AddRng(0x00, 0x20, TFeature::FeatureEncodeCntrl); @@ -67,11 +67,11 @@ namespace NUri { Add(' ', TFeature::FeatureEncodeSpace | TFeature::FeatureEncodeSpaceAsPlus); Add("'\"\\", TFeature::FeatureEncodeForSQL); - GetMutable(':').EncodeFld |= TField::FlagUser; - GetMutable('?').EncodeFld |= TField::FlagPath; - GetMutable('#').EncodeFld |= TField::FlagPath | TField::FlagQuery; - GetMutable('&').EncodeFld |= TField::FlagQuery; - GetMutable('+').EncodeFld |= TField::FlagQuery; + GetMutable(':').EncodeFld |= TField::FlagUser | TField::FlagHashBang; + GetMutable('?').EncodeFld |= TField::FlagPath | TField::FlagHashBang; + GetMutable('#').EncodeFld |= TField::FlagPath | TField::FlagQuery | TField::FlagHashBang; + GetMutable('&').EncodeFld |= TField::FlagQuery | TField::FlagHashBang; + GetMutable('+').EncodeFld |= TField::FlagQuery | TField::FlagHashBang; } // should we decode an encoded character diff --git a/library/cpp/uri/http_url.h b/library/cpp/uri/http_url.h index 7c8e8d844d..ac12da13ec 100644 --- a/library/cpp/uri/http_url.h +++ b/library/cpp/uri/http_url.h @@ -27,8 +27,8 @@ public: { } - THttpURL(const TStringBuf& host, ui16 port, const TStringBuf& path, const TStringBuf& query = TStringBuf(), const TStringBuf& scheme = "http", unsigned defaultPort = 0) - : TUri(host, port, path, query, scheme, defaultPort) + THttpURL(const TStringBuf& host, ui16 port, const TStringBuf& path, const TStringBuf& query = TStringBuf(), const TStringBuf& scheme = "http", unsigned defaultPort = 0, const TStringBuf& hashbang = TStringBuf()) + : TUri(host, port, path, query, scheme, defaultPort, hashbang) { } diff --git a/library/cpp/uri/parse.cpp b/library/cpp/uri/parse.cpp index 1db4e008c4..ee45a5b558 100644 --- a/library/cpp/uri/parse.cpp +++ b/library/cpp/uri/parse.cpp @@ -42,6 +42,11 @@ namespace NUri { , TParseFlags(0 // FieldFragment | TFeature::FeaturesEncodePChar, + 0 | TFeature::FeatureToLower | TFeature::FeatureEncodeSpaceAsPlus) + + , + TParseFlags(0 // FieldHashBang + | TFeature::FeaturesEncodePChar, 0 | TFeature::FeatureToLower | TFeature::FeatureEncodeSpaceAsPlus)}; namespace NParse { diff --git a/library/cpp/uri/uri.cpp b/library/cpp/uri/uri.cpp index 962e84e7a1..d0fcf71bb5 100644 --- a/library/cpp/uri/uri.cpp +++ b/library/cpp/uri/uri.cpp @@ -55,7 +55,7 @@ namespace NUri { } /********************************************************/ - TUri::TUri(const TStringBuf& host, ui16 port, const TStringBuf& path, const TStringBuf& query, const TStringBuf& scheme, unsigned defaultPort) + TUri::TUri(const TStringBuf& host, ui16 port, const TStringBuf& path, const TStringBuf& query, const TStringBuf& scheme, unsigned defaultPort, const TStringBuf& hashbang) : FieldsSet(0) , Port(port) , DefaultPort(0) @@ -79,6 +79,7 @@ namespace NUri { FldTrySet(FieldHost, host); FldTrySet(FieldPath, path); FldTrySet(FieldQuery, query); + FldTrySet(FieldHashBang, hashbang); Rewrite(); } @@ -233,6 +234,9 @@ namespace NUri { if (noscheme && IsNull(FlagQuery) && IsNull(FlagPath)) FldTrySet(FieldQuery, base); + if (noscheme && IsNull(FlagHashBang) && IsNull(FlagPath)) + FldTrySet(FieldHashBang, base); + if (IsNull(FlagAuth) && !base.IsNull(FlagAuth)) { FldChkSet(FieldUser, base); FldChkSet(FieldPass, base); @@ -320,7 +324,7 @@ namespace NUri { } // find out if it is link to itself then ignore it - if (!Compare(base, FlagPath | FlagQuery)) + if (!Compare(base, FlagPath | FlagQuery | FlagHashBang)) return LinkIsFragment; return LinkIsLocal; @@ -424,6 +428,12 @@ namespace NUri { out << '#' << v; } + if (flags & FlagHashBang) { + v = Fields[FieldHashBang]; + if (v.IsInited()) + out << '#' << '!' << v; + } + return out; } diff --git a/library/cpp/uri/uri.h b/library/cpp/uri/uri.h index 71fc687fc2..b7550a9e2c 100644 --- a/library/cpp/uri/uri.h +++ b/library/cpp/uri/uri.h @@ -257,7 +257,7 @@ namespace NUri { { } - TUri(const TStringBuf& host, ui16 port, const TStringBuf& path, const TStringBuf& query = TStringBuf(), const TStringBuf& scheme = "http", unsigned defaultPort = 0); + TUri(const TStringBuf& host, ui16 port, const TStringBuf& path, const TStringBuf& query = TStringBuf(), const TStringBuf& scheme = "http", unsigned defaultPort = 0, const TStringBuf& hashbang = TStringBuf()); TUri(const TUri& url) : FieldsSet(url.FieldsSet) |