@@ -3,13 +3,51 @@ const GITHUB_ISSUES_URL =
33 ? 'https://github.com/w3c/aria-at'
44 : 'https://github.com/bocoup/aria-at' ;
55
6+ // Maximum URL length for GitHub issues
7+ // Tested on multiple browsers and devices
8+ const MAX_GITHUB_URL_LENGTH = 8000 ;
9+
610// TODO: Use At.key
711const atLabelMap = {
812 'VoiceOver for macOS' : 'vo' ,
913 JAWS : 'jaws' ,
1014 NVDA : 'nvda'
1115} ;
1216
17+ /**
18+ * Returns a truncation message for URLs that are too long.
19+ *
20+ * @param {number|null } testSequenceNumber - Optional test sequence number to include in truncation message
21+ * @returns {string } The truncation message
22+ */
23+ const getTruncationMessage = ( testSequenceNumber = null ) => {
24+ return `...\n\n[**Content truncated due to URL length limits.** Please visit [${
25+ window . location
26+ } ](${ window . location } ) to review ${
27+ ! testSequenceNumber ? 'further' : `Test ${ testSequenceNumber } `
28+ } .]`;
29+ } ;
30+
31+ /**
32+ * Truncates a body string to ensure the resulting URL stays under the maximum length.
33+ *
34+ * @param {string } body - The original body content
35+ * @param {string } baseUrl - The URL without the body (including title and labels)
36+ * @param {number|null } testSequenceNumber - Optional test sequence number to include in truncation message
37+ * @returns {string } The truncated body that will keep the URL under the maximum length
38+ */
39+ const truncateUrlBody = ( body , baseUrl , testSequenceNumber = null ) => {
40+ const maxUrlLength = MAX_GITHUB_URL_LENGTH ;
41+ const truncationMessage = getTruncationMessage ( testSequenceNumber ) ;
42+
43+ // Multiply by 0.65 to account for encoding
44+ const maxBodyLength = Math . floor (
45+ ( maxUrlLength - baseUrl . length - truncationMessage . length ) * 0.65
46+ ) ;
47+
48+ return body . substring ( 0 , maxBodyLength ) + truncationMessage ;
49+ } ;
50+
1351/**
1452 * Creates a link to open a new issue on the GitHub repository.
1553 *
@@ -183,10 +221,19 @@ const createIssueLink = ({
183221 body += `\n${ conflictMarkdown } ` ;
184222 }
185223
186- return (
187- `${ GITHUB_ISSUES_URL } /issues/new?title=${ encodeURI ( title ) } &` +
188- `labels=${ labels } &body=${ encodeURIComponent ( body ) } `
189- ) ;
224+ // Create the base URL without the body
225+ const baseUrl = `${ GITHUB_ISSUES_URL } /issues/new?title=${ encodeURI (
226+ title
227+ ) } &labels=${ labels } &body=`;
228+
229+ let url = baseUrl + encodeURIComponent ( body ) ;
230+
231+ if ( url . length > MAX_GITHUB_URL_LENGTH ) {
232+ body = truncateUrlBody ( body , baseUrl , testSequenceNumber ) ;
233+ url = baseUrl + encodeURIComponent ( body ) ;
234+ }
235+
236+ return url ;
190237} ;
191238
192239/**
0 commit comments