Skip to content

Conversation

@vaskkey
Copy link
Contributor

@vaskkey vaskkey commented Sep 26, 2025

Marked version:

16.3.0

Markdown flavor: Markdown.pl|CommonMark|GitHub Flavored Markdown|n/a

Description

Expectation

When a link starts with www. (in any case combination like Www., WWW., etc.), it should be automatically converted to a clickable link with http:// prepended.

Result

Before the fix, only lowercase www. was being prepended with http://. Links starting with Www. or other case variations were being processed as autolinks but did not have http:// prepended, which caused the links to redirect to http://mainwebsite/Www.foo.com.

After the fix, both www.foo.com and Www.foo.com are now properly converted to <a href="http://www.foo.com">www.foo.com</a> and <a href="http://Www.foo.com">Www.foo.com</a> respectively.

What was attempted

The fix was implemented in src/Tokenizer.ts:843 by changing the strict equality check from:

if (cap[1] === 'www.') {

to a case-insensitive comparison:

if (cap[1]?.toLowerCase() === 'www.') {

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR): Added cases to autolinks.md

Committer

In most cases, this should be a different person than the contributor.

@vercel
Copy link

vercel bot commented Sep 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
marked-website Ready Ready Preview Comment Sep 26, 2025 0:43am

@gemini-code-assist
Copy link

Summary of Changes

Hello @vaskkey, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where the autolinking mechanism failed to correctly prepend the "http://" protocol to URLs that began with a case-insensitive "www." prefix. By updating the tokenizer's logic to perform a case-insensitive check, the system now ensures that all variations of "www." (e.g., "Www.", "WWW.") are properly recognized and converted into fully functional, clickable links, preventing broken redirections.

Highlights

  • Case-insensitive www. prefix handling: The pull request modifies the autolinking logic to correctly prepend "http://" to URLs starting with "www." regardless of their casing (e.g., "Www.", "WWW.").
  • Fix for broken autolinks: Previously, only lowercase "www." was recognized, causing links like "Www.foo.com" to not have "http://" prepended, resulting in incorrect redirection.
  • Implementation detail: The fix involves changing a strict equality check (cap[1] === 'www.') to a case-insensitive comparison (cap[1]?.toLowerCase() === 'www.') in src/Tokenizer.ts.
  • Test coverage: New test cases have been added to test/specs/new/autolinks.md and test/specs/new/autolinks.html to validate the corrected behavior for various www. casings.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes an issue where www. prefixes in URLs were not handled case-insensitively for autolinking. The change correctly identifies prefixes like Www. and prepends http://. The implementation is correct according to the goal, and new tests are added to cover the case-insensitive scenarios. I have one suggestion for improvement regarding URL normalization for better standards compliance.

} while (prevCapZero !== cap[0]);
text = cap[0];
if (cap[1] === 'www.') {
if (cap[1]?.toLowerCase() === 'www.') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This change correctly handles case-insensitive www. prefixes. However, the generated href preserves the original casing of the domain (e.g., http://Www.foo.com).

According to RFC 3986, the host component of a URI is case-insensitive. It is a best practice to normalize it to lowercase in the href attribute for consistency and to prevent potential issues. The visible link text should preserve the original user input.

You could consider updating the logic inside this if block to normalize the domain part of the URL. Here's a possible implementation:

// inside the if (cap[1]?.toLowerCase() === 'www.') block
const pathStartIndex = cap[0].search(/[\/?#]/);
const domain = pathStartIndex === -1 ? cap[0] : cap[0].substring(0, pathStartIndex);
const path = pathStartIndex === -1 ? '' : cap[0].substring(pathStartIndex);
href = 'http://' + domain.toLowerCase() + path;

If you apply this change, please remember to update the corresponding test case in test/specs/new/autolinks.html to expect a lowercase href.

@UziTech
Copy link
Member

UziTech commented Sep 26, 2025

Autolink is a GFM extension so we want it to act the same as GitHub and it looks like GitHub doesn't allow the www to be case insensitive.

www.example.com
Www.example.com
WWW.example.com

If this is something you want you can create a custom extension

@vaskkey
Copy link
Contributor Author

vaskkey commented Sep 26, 2025

@UziTech In that case I could probably configure the autolink to be a bit stricter than it is right now. because currently for Www.example.com marked generates <a href="Www.example.com">Www.example.com</a> which is neither a good link nor a GitHub way of parsing links

@UziTech
Copy link
Member

UziTech commented Sep 27, 2025

Good call. Ya that sounds good. We want it to be the same as GitHub

@vaskkey
Copy link
Contributor Author

vaskkey commented Sep 29, 2025

Closing this PR, Github-like implementation here: #3770

@vaskkey vaskkey closed this Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants