fix: move uri encoding to formatArgs#110
Conversation
|
Is this change breaking? |
|
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". |
|
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(); |
|
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 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 But If you do think this PR will cause problems, I'm happy to hear more details! |
|
Thank you! |
|
You're welcome, and thanks for the clear example! |
joneugster
left a comment
There was a problem hiding this comment.
Thank you for the fix!
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. |
Resolves #109.
Moves the responsibility for calling
fixedEncodeURIComponenttoformatArgs. I tried to ensure that there's no double-encoding happening as a result of this change. I don't see any other callers offixedEncodeURIComponentorencodeURIComponentafter this change.I locally tested that the behavior in #109 is eliminated. I tried copying and pasting well-formed
code=andcodez=URIs, editing, changing projects, Import-from-file functionality.