Created
December 23, 2025 19:10
-
-
Save jaredkrinke/d08693e5fbcf88d85c59786defca382c to your computer and use it in GitHub Desktop.
Script to find upper bound on URL fragment length
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <body> | |
| <pre id="log"></pre> | |
| <script> | |
| const d = document.getElementById("log"); | |
| function log(text) { d.appendChild(document.createTextNode(text + "\n")); } | |
| function underLimit(n) { | |
| try { | |
| let url = new URL("http://www.example.com/foo.html" + ("#" + "a".repeat(n - 1))); | |
| return true; | |
| } catch { | |
| return false; | |
| } | |
| } | |
| let lower, upper; | |
| function findLimit() { | |
| if ((upper - lower) > 1) { | |
| let mid = Math.floor((upper + lower) / 2); | |
| if (underLimit(mid)) { | |
| lower = mid; | |
| } else { | |
| upper = mid; | |
| } | |
| log(`${lower} - ${upper}`); | |
| setTimeout(() => findLimit(), 0); | |
| } else { | |
| log(lower); | |
| } | |
| } | |
| let n = 1024; | |
| function findLimits() { | |
| if (underLimit(n)) { | |
| log(n); | |
| n *= 2; | |
| setTimeout(() => findLimits(), 0); | |
| } else { | |
| lower = n / 2; | |
| upper = n; | |
| findLimit(); | |
| } | |
| } | |
| findLimits(); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment