Skip to content

Image links printed lowercased, breaking case-sensitive URLs #2

@thegoodentity

Description

@thegoodentity

Where

src/index.ts (image link handling):

const responseText = result.response?.toLowerCase() ?? "";
const imageRegex = /(https?:\/\/.*\.(?:png|jpg|gif))/gi;
const images = responseText.match(imageRegex);
if (images) {
console.log(orange("\nImage links:"));
images.forEach((img) => console.log(orange(`- ${img}`)));

const responseText = result.response?.toLowerCase() ?? "";
const imageRegex = /(https?:\/\/.*\.(?:png|jpg|gif))/gi;
const images = responseText.match(imageRegex);
if (images) {
  console.log(orange("\nImage links:"));
  images.forEach((img) => console.log(orange(`- ${img}`)));
}

Problem

The regex is matched against result.response.toLowerCase(), so the printed links come from the lowercased copy. Any URL with case-sensitive parts is corrupted:

input:  https://cdn.Example.com/AbC123/Img.PNG
shown:  https://cdn.example.com/abc123/img.png

This breaks links to case-sensitive hosts or paths (S3 keys, IPFS gateways, signed URLs with case-sensitive tokens, etc.).

Secondary: the extension list misses common image types such as .jpeg, .webp, and .svg.

Suggested fix

Match against the original response, not the lowercased copy:

const responseText = result.response ?? "";
const imageRegex = /(https?:\/\/\S+\.(?:png|jpe?g|gif|webp|svg))/gi;
const images = responseText.match(imageRegex);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions