Commit 91ffe1e8 authored by jan.koester's avatar jan.koester
Browse files

test

parent ef24ffa1
Loading
Loading
Loading
Loading
+28 −1
Original line number Diff line number Diff line
@@ -5144,8 +5144,35 @@ static std::string guessImageExtFromBytes(const std::vector<std::uint8_t> &bytes
    return "webp";
}

// CSS url() scanning (see this function's two CustomCss/globalCss call
// sites below) can't distinguish a background-image from an @font-face src
// -- both use identical url(...) syntax -- so without this every webfont a
// page's CSS references gets treated as an image to re-host, then fails the
// media-import fetch's "image/" Content-Type check and shows up to the user
// as an inexplicable "N Bild(er) fehlgeschlagen" for files that were never
// images (confirmed against a real page: 21 of 55 collected "image" urls
// were manrope .woff/.woff2/.ttf webfonts from its @font-face rules, the
// exact 21 that always failed). Filtered by extension since that's known
// before ever making the request; genuine images with no extension at all
// (common on CDNs, see guessImageExtFromBytes) still pass through untouched
// -- this only excludes the handful of extensions that are unambiguously
// never an image.
static bool isExternalImageUrl(const std::string &s) {
    return s.compare(0, 7, "http://") == 0 || s.compare(0, 8, "https://") == 0;
    if (s.compare(0, 7, "http://") != 0 && s.compare(0, 8, "https://") != 0) return false;

    static const std::vector<std::string> nonImageExts = {
        ".woff2", ".woff", ".ttf", ".otf", ".eot"
    };
    std::string path = s;
    size_t q = path.find_first_of("?#");
    if (q != std::string::npos) path.resize(q);
    for (const auto &ext : nonImageExts) {
        if (path.size() >= ext.size() &&
            std::equal(ext.begin(), ext.end(), path.end() - ext.size(),
                       [](char a, char b) { return std::tolower(static_cast<unsigned char>(a)) == b; }))
            return false;
    }
    return true;
}

// Recursively collects every distinct absolute http(s) `src` from the