Skip to content

fix: move uri encoding to formatArgs#110

Merged
joneugster merged 1 commit into
leanprover-community:mainfrom
jcreedcmu:jcreed/urlencode
May 14, 2026
Merged

fix: move uri encoding to formatArgs#110
joneugster merged 1 commit into
leanprover-community:mainfrom
jcreedcmu:jcreed/urlencode

Conversation

@jcreedcmu
Copy link
Copy Markdown
Contributor

Resolves #109.

Moves the responsibility for calling fixedEncodeURIComponent to formatArgs. I tried to ensure that there's no double-encoding happening as a result of this change. I don't see any other callers of fixedEncodeURIComponent or encodeURIComponent after this change.

I locally tested that the behavior in #109 is eliminated. I tried copying and pasting well-formed code= and codez= URIs, editing, changing projects, Import-from-file functionality.

@Seasawher
Copy link
Copy Markdown

Is this change breaking?

@jcreedcmu
Copy link
Copy Markdown
Contributor Author

I don't believe this violates any guarantee lean4web is making to the user or downstream code... But do correct me if I'm wrong in assuming the representation of the various jotai atoms used to hold url state is intended as "public api".

@Seasawher
Copy link
Copy Markdown

Seasawher commented May 13, 2026

I run the following code for my online book. This may break?

function filePlay() {
  const playButtonIcon = document.querySelector("#lean-play-button");

  const playButtonLink = playButtonIcon.parentElement;

  playButtonLink.href = playButtonLink.href.replace(/\.md$/, ".lean");

  playButtonLink.href = playButtonLink.href.replace(
    "/booksrc/",
    "/LeanByExample/",
  );

  fetch(playButtonLink.href)
    .then((response) => response.text())
    .then((body) => {
      const escaped_code = encodeURIComponent(body);
      const url = `https://live.lean-lang.org/#code=${escaped_code}`;
      playButtonLink.href = url;
    });
}

filePlay();

@jcreedcmu
Copy link
Copy Markdown
Contributor Author

jcreedcmu commented May 13, 2026

I don't think it should break with this PR!

My intention and understanding of my code in this PR is that this use case would still work. The code that decodes the uri-encoded ${escaped_code} in links such as https://live.lean-lang.org/#code=${escaped_code} should be unaffected by this change.

The purpose of the PR is to ensure that when running instances of lean4web (such as https://live.lean-lang.org/) themselves produce URIs that are of the form #code=${escaped_code} (and this will naturally happen as you edit the code in the code editor if you have compression turned off in your settings) that the code in those URIs are always correctly uri-encoded. See the attached issue for an example of what can go wrong today.

But If you do think this PR will cause problems, I'm happy to hear more details!

@Seasawher
Copy link
Copy Markdown

Thank you!

@jcreedcmu
Copy link
Copy Markdown
Contributor Author

You're welcome, and thanks for the clear example!

Copy link
Copy Markdown
Collaborator

@joneugster joneugster left a comment

Choose a reason for hiding this comment

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

Thank you for the fix!

@joneugster
Copy link
Copy Markdown
Collaborator

Is this change breaking?

Repeating what jcreedcmu said, this doesn't change the public API: any valid URL will still be valid.

It only fixes a clear bug in the link generation.

@joneugster joneugster merged commit 5143c4d into leanprover-community:main May 14, 2026
5 checks passed
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.

bug: insufficient url escaping leads to missing code when switching projects

3 participants