Skip to content

Commit eea4b7e

Browse files
Updated Safari hack to target 15.0-15.3 (#1347) (#1414)
1 parent 89ea606 commit eea4b7e

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

‎src/App.h‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,24 @@ namespace uWS {
3535
bool compress;
3636
};
3737

38+
/* Safari 15.0 - 15.3 has a completely broken compression implementation (client_no_context_takeover not
39+
* properly implemented) - so we fully disable compression for this browser :-(
40+
* see https://github.com/uNetworking/uWebSockets/issues/1347 */
3841
inline bool hasBrokenCompression(std::string_view userAgent) {
39-
size_t pos;
40-
int uaVersion = 0;
42+
size_t posStart = userAgent.find(" Version/15.");
43+
if (posStart == std::string_view::npos) return false;
44+
posStart += 12;
4145

42-
if ((pos = userAgent.find(" Version/")) == std::string_view::npos) return false;
43-
pos += 9;
46+
size_t posEnd = userAgent.find(' ', posStart);
47+
if (posEnd == std::string_view::npos) return false;
4448

45-
std::string_view uaVersionStr = userAgent.substr(pos);
46-
uaVersionStr = uaVersionStr.substr(0, uaVersionStr.find_first_of(". "));
47-
auto result = std::from_chars(uaVersionStr.data(), uaVersionStr.data() + uaVersionStr.size(), uaVersion);
48-
if (result.ec == std::errc::invalid_argument) return false;
49-
if (uaVersion != 15) return false; // we target just Safari 15 - give Apple a chance ;-)
49+
unsigned int minorVersion = 0;
50+
auto result = std::from_chars(userAgent.data() + posStart, userAgent.data() + posEnd, minorVersion);
51+
if (result.ec != std::errc()) return false;
52+
if (result.ptr != userAgent.data() + posEnd) return false; // do not accept trailing chars
53+
if (minorVersion > 3) return false; // we target just Safari 15.0 - 15.3
5054

51-
if ((pos = userAgent.find(" Safari/", pos)) == std::string_view::npos) return false;
55+
if (userAgent.find(" Safari/", posEnd) == std::string_view::npos) return false;
5256

5357
return true;
5458
}

0 commit comments

Comments
 (0)