[Due for payment 2026-11-11] [$175] Compose Box - Maximum comment length error when a link is pasted in the composer
If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
Version Number: v9.4.95-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://github.com/Expensify/App/pull/100421 Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Pull Request QA execution Device used: Windows 11/ Chrome, Samsung S23FE/ Android 16, iPhone 13 Mini/ iOS 26.5 App Component: Chat Report View
Action Performed:
- Navigate to https://staging.new.expensify.com/
- Go to any 1:1 chat
- Open Chrome DevTools and select the Console tab
- Run: copy('a'.repeat(8496) + '.com')
- Paste the string in the composer
Expected Result:
The maximum comment length error message is not displayed.
Actual Result:
The maximum comment length error message is displayed, but the writing is still allowed. The pasted message is 8,500 characters long.
Workaround:
Unknown
Platforms:
- [x] Android: App
- [ ] Android: mWeb Chrome
- [x] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [x] Windows: Chrome
- [ ] MacOS: Chrome Safari
Screenshots/Videos
https://github.com/user-attachments/assets/6cc42470-5e3c-4038-b788-f4d18c2fcf06
Applause Internal Information Exported by: Julia Ponikarchuk Bug ID: 7272030
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022104830733949161960
- Upwork Job ID: 2104830733949161960
- Last Price Increase: 2026-09-29
Issue Owner
Current Issue Owner: @Uzaifm127
While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/1dfad893b0feb7d2629ca1f27f01fe7c0b49d24b419b4994a903b58eecf58042
Proposal
What is the root cause of that problem?
The length check counts the message's HTML, not the characters you see. ExpensiMark turns the pasted string into a link, so the text appears twice in the HTML (<a href="https://aaa…com" …>aaa…com</a>). The 8,500 visible characters become 17,065 HTML characters, which is over the 15,000 limit.
getCommentLengthmeasures the parsed HTML on purpose, so the App matches how the backend countsAddCommentlength.- The real bug is in expensify-common.
URL_WEBSITE_REGEXaccepts hostname labels of any length ([-a-z0-9]*). DNS allows at most 63 characters per label, soaaa…(8,496)….comis not a real domain and should never become a link.
Typing still works because the input's hard cap counts raw characters (MAX_COMMENT_LENGTH + 1). The HTML check only blocks sending.
This is not a regression from fix: preserve Markdown formatting in long messages. expensify-common 2.0.204, the version before that PR, gives the same 17,065-character output.
What changes do you think we should make in order to solve the problem?
Change expensify-common, then bump it in App:
- In
URL_WEBSITE_REGEX, limit each hostname label to 63 characters ([-a-z0-9]{0,61}in place of[-a-z0-9]*). - Add a lookbehind so a match can't start in the middle of a label (
(?<![-a-z0-9.])). Without it, the regex links just the last 63 characters of the string. - Apply the same 63-character rule in the new candidate scanner (
isValidHostnameLabel/findHostnameStartinExpensiMark.ts) so both paths agree. - Add unit tests: a 63-character label links, a 64-character label does not, and common URLs still link.
With these changes, the pasted string stays plain text and counts as 8,500 characters, so no error appears.
What alternative solutions did you explore? (Optional)
- Count raw characters in App. This breaks parity with the backend. The HTML count was added on purpose to stop
AddCommentfrom failing. - Override the autolink rule in App's
Parser.ts. This is a workaround, and the composer's live Markdown highlighting would still show the link.
Investigation details
The researcher ran the real getCommentLength in a Jest test on App 68ad1ed:
| Input | getCommentLength |
|---|---|
'a'.repeat(8496) + '.com' |
17,065 (over 15,000) |
'a'.repeat(8500) |
8,500 |
| Same output from expensify-common 2.0.204 and 2.0.207 | Yes |
- The link adds 65 characters plus a second copy of the URL: HTML length = 2 × length + 65. Any bare "domain" of 7,468 or more characters triggers the error.
- Text over
MAX_MARKUP_LENGTH(10,000) is not parsed (ReportUtils.ts:6933). So the same string at 10,001 or more characters does not show the error. - The composer blocks sending when the limit is exceeded (
useDebouncedCommentMaxLengthValidation.ts:38). - We tested the 63-character cap plus lookbehind by overriding the regex in Jest. The 8,500-character string was not linked.
google.com,https://www.expensify.com/path?x=1,sub.domain.example.co.uk,[email protected], and_expensify.com_still behaved as before. - A live web reproduction didn't finish because the test session's page went blank. The Jest run above calls the same code the composer uses.
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/102500) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @thelullabyy (External)
Job added to Upwork: https://www.upwork.com/jobs/~022104830733949161960
Proposal
Please re-state the problem that we are trying to solve in this issue.
When pasting an 8,500-character string formatted like a pseudo-domain (e.g. 'a'.repeat(8496) + '.com') into the composer, the "Maximum comment length exceeded" error message is prematurely displayed even though the raw text is well within the 10,000 character limit.
What is the root cause of that problem?
- In
src/libs/ReportUtils.ts:10798-10802,getCommentLengthcomputes comment length on the parsed HTML output viaExpensiMark(rather than raw plaintext characters) to ensure parity with the backend auth validator forAddComment:function getCommentLength(textComment: string, parsingDetails?: ParsingDetails): number { return getParsedComment(textComment, parsingDetails) .replaceAll(/[^ -~]/g, '\u????') .trim().length; } - When the user pastes
'a'.repeat(8496) + '.com',ExpensiMarkinexpensify-commonappliesURL_WEBSITE_REGEX([-a-z0-9]*\.[a-z]{2,}). - Under RFC 1035 and DNS specifications, a valid domain label cannot exceed 63 characters. However, the current regex in
expensify-commonallows unlimited characters in the label ([-a-z0-9]*). - Because the 8,496-character string is incorrectly recognized as a URL,
ExpensiMarkautolinks it, duplicating the string in bothhrefand inner text:<a href="https://aaaa...com" target="_blank" rel="noreferrer noopener">aaaa...com</a> - This balloons the 8,500 visible characters into 17,065 HTML characters, which exceeds the backend and client limit (15,000 HTML characters /
CONST.MAX_COMMENT_LENGTH), triggeringuseDebouncedCommentMaxLengthValidation.ts:38-41to flag a maximum length violation.
What changes do you think we should make in order to solve the problem?
- Enforce RFC 1035 63-Character Label Limit in
expensify-common(andExpensiMark.ts):- Update
URL_WEBSITE_REGEXinexpensify-common/lib/Url.js(andsrc/libs/ExpensiMark.ts) to restrict domain label length to a maximum of 63 characters: Replace[-a-z0-9]*with[-a-z0-9]{1,63}and include boundary checks:const URL_WEBSITE_REGEX = /(?<![-a-z0-9.])(?:[a-z0-9](?:[-a-z0-9]{0,61}[a-z0-9])?\.)+[a-z]{2,}/gi; - In
ExpensiMark.ts, enforcelabel.length <= 63in hostname label validation (isValidHostnameLabel).
- Update
- Result:
- Any string with an unsegmented label exceeding 63 characters (such as
a.repeat(8496) + '.com') will not be treated as a website link. - It remains plain text of 8,500 characters, well within the limit, preventing the false "maximum comment length exceeded" error.
- Any string with an unsegmented label exceeding 63 characters (such as
- Add Unit Tests in
tests/unit/ExpensiMarkTest.ts:- Verify that domain labels <= 63 characters are correctly autolinked.
- Verify that domain labels > 63 characters remain plain text and do not inflate HTML length.
What alternative solutions did you explore? (Optional)
- Calculating comment length purely on raw text in the client: Explored and rejected because if a message containing legitimate Markdown/links exceeds the backend 15,000 HTML limit, the server would reject the
AddCommentcommand with an error. Enforcing the RFC 63-character hostname standard inExpensiMarkfixes the root autolinking defect while maintaining full client-backend length parity.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0139ed4098bdc50182
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
@JS00001
Can me and @linhvovan29546 work on this issue? Because
This issue was found during QA for our PR: https://github.com/Expensify/App/pull/100421, and I already faced this issue locally while solving the long .comx and heavy dotted URL case for ExpensiMark follow up PR: https://github.com/Expensify/expensify-common/pull/945. Since it isn't a regression introduced by our PR, solving this issue also includes updating the candidate scanning logic introduced by our ExpensiMark performance PR: https://github.com/Expensify/expensify-common/pull/937
Since we already have the full context and idea for these parser changes, happy to be assigned. Thank you!
Works for me
📣 @Uzaifm127 You have been assigned to this job! Please apply to the Upwork job and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑💻 Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs! Keep in mind: Code of Conduct | Contributing 📖
Thanks @JS00001 for the assignment here.
I'll raise a PR on tomorrow or the day after tomorrow, thanks.
@linhvovan29546 I wanna clarify something before raising the PR for this.
The problem we are currently facing is that the composer can show the 15,000 character error even when the text entered by the user is much shorter than 15,000 characters. According to the OP, this happens with one very long URL, but it is not limited to URLs. When I checked manually then it also happens with other Markdown formatting. For example:
copy('*a* '.repeat(2000))
This pastes 8,000 characters into the composer. However, each *a* is converted into <strong>a</strong>, so the final parsed message becomes around 38,000 characters. The user therefore sees a 15,000 character error while only seeing 8,000 characters in the composer.
From what I found, the composer passes its Markdown text to the length validation, which then calls getParsedComment() and Parser.replace() before checking the length https://github.com/Expensify/App/blob/e5564c4dc4545c8e1c682cde8e47b423b83db032/src/libs/ParsingUtils.ts#L111-L115 This means we are validating the parsed HTML instead of the Markdown visible in the composer. We do this because the parsed HTML is sent to the backend and thats how it is stored in the database: https://github.com/Expensify/App/blob/7fffddb00a4678fd16154cfe18b74fdd515f0a2f/src/libs/ReportUtils.ts#L6922-L6925 We don't know why we are storing the parsed HTML in DB instead of Markdown. Initially, I thought we could solve this by validating the Markdown text in the composer, but that is not ideal because the parsed HTML is sent to the backend and the backend applies the 15,000-character limit to that parsed HTML. I tried validating only the Markdown from the composer, but then the frontend allowed the 8,000 character message and the backend rejected it because its parsed HTML was over 15,000 characters.
Here is the error returned by the backend when the composer has fewer than 15,000 characters but the parsed HTML exceeds the limit:
So basically, there would be a difference between what the composer allows and what the backend allows: the composer could allow a message under 15,000 Markdown characters, but the backend could reject it after it is parsed into HTML.
Because of this, checking only the Markdown length won't solve the issue. For the URL case from the OP, we can prevent invalid oversized hostnames from being converted into links by checking both the limit for each hostname label and the complete hostname. For the remaining cases where valid Markdown produces HTML longer than 15,000 characters, I think we should keep the parsed HTML validation but use two different error messages:
[!NOTE] Two different error messages for limit because the end user would think if composer allows 15k characters at max then why the common error message (for maximum composer limit) is appearing.
- Keep the existing error when the actual composer text exceeds 15,000 characters.
- Show a different error message when the composer text is below 15,000 characters but the parsed message exceeds the backend limit because of its formatting, so that the end user wouldn't be confused.
@linhvovan29546 Does this approach sound good? If so, I can proceed with the URL validation, and we can confirm the second error message with the design team before implementing it.
I think we should scope the PR to just the hostname-label-length fix and keep the existing single error message as-is. It’s difficult to trigger with normal typing. Nobody is going to organically type *a* two thousand times. It requires a deliberately adversarial paste, exactly like the QA repro, to hit that 2x+ HTML expansion ratio. Real users with normal formatting (a few bold words and a couple of links) won’t get close to the 15k boundary.
@JS00001 What are your thoughts on this?
I think we should scope the PR to just the hostname-label-length fix and keep the existing single error message as-is
I agree. We shouldnt spend a bunch of time fixing the cases that wont really ever be hit
Update: The draft PR is up in expensify-common.
I'm doing the local testing and reviewing the PR locally from my side, after that I'll mark the PR ready for review.
Thanks.
Update: The PR is WIP.
Not overdue
@linhvovan29546 The PR in expensify-common is ready for review. Thanks.
@linhvovan29546 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
Not overdue
@linhvovan29546 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!