Skip to content

Commit a6f5c9f

Browse files
stalgiaghoward-e
andauthored
fix: Revise length of generated GitHub issue link to avoid hitting URI max length (#1336)
Limit length of encoded body included in generated GitHub Issue URI --------- Co-authored-by: Howard Edwards <[email protected]>
1 parent b1a8483 commit a6f5c9f

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

client/components/CandidateReview/CandidateModals/NotApprovedModal/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const NotApprovedModal = ({ handleAction = () => {}, githubUrl = '#' }) => {
1515
<>
1616
<p className="review-confirmation-content">Thank you for reviewing</p>
1717
<p className="review-confirmation-share">
18-
if you haven’t opened any issues yet, please{' '}
18+
If you haven’t opened any issues yet, please{' '}
1919
<a href={githubUrl} target="_blank" rel="noreferrer">
2020
open an issue describing why this is not approved.
2121
</a>

client/components/CandidateReview/CandidateTestPlanRun/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ const CandidateTestPlanRun = () => {
360360
isCandidateReviewChangesRequested: false,
361361
testTitle: undefined,
362362
testRowNumber: undefined,
363+
testSequenceNumber: undefined,
363364
testRenderedUrl: undefined
364365
});
365366

client/utils/createIssueLink.js

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
711
const 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

Comments
 (0)