Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scripts/story-dialog.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ test("story over 1500 chars is trimmed in the form URL and the user is told", ()
assert.match(t.el("story-status").textContent, /^Your story was trimmed to 1500 characters/);
});

test("story cut inside an emoji drops the half pair so the form URL still opens", () => {
const t = boot();
t.fill({ ...VALID, "story-text": "a".repeat(STORY_MAX - 1) + "😀 tail" });
t.submit();
assert.equal(t.opened.length, 1, "submit opens the draft issue instead of throwing URIError");
assert.equal(t.issueUrl().searchParams.get("story"), "a".repeat(STORY_MAX - 1));
});

test("story at exactly 1500 chars is not trimmed", () => {
const t = boot();
t.fill({ ...VALID, "story-text": "y".repeat(STORY_MAX) });
Expand Down
7 changes: 5 additions & 2 deletions stories/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-e2g5HkZP+fghbsY1m7moq4GopOo7zRRaAHNyQ2Q7oSI=' 'sha256-CopZnncCKanV2SsMcCJvI3+3dnyMsvxzc3p4UWbNXkc=' 'unsafe-hashes' 'sha256-Kkh0ufQbkIVTWPYjIGk2bAJsmDwjmUuIAt2LyPfNr3g='; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://github.com https://avatars.githubusercontent.com; font-src 'self'; base-uri 'none'; form-action 'self'">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-e2g5HkZP+fghbsY1m7moq4GopOo7zRRaAHNyQ2Q7oSI=' 'sha256-ycRNP2kNHazBu8LXdhFNDrNJfr5JYNooQIqUE+oWqyE=' 'unsafe-hashes' 'sha256-Kkh0ufQbkIVTWPYjIGk2bAJsmDwjmUuIAt2LyPfNr3g='; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://github.com https://avatars.githubusercontent.com; font-src 'self'; base-uri 'none'; form-action 'self'">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>Contributor Stories — Hive Commons</title>
<meta name="description" content="Real Hive Commons contributor progression stories and public Contributor Relay metrics for event organisers, mentors, and contributors.">
Expand Down Expand Up @@ -378,7 +378,10 @@ <h2 id="story-dialog-title">Open a contributor story draft</h2>

function truncateStory(story) {
if (story.length <= STORY_MAX) return { text: story, truncated: false };
return { text: story.slice(0, STORY_MAX).trimEnd(), truncated: true };
var cut = story.slice(0, STORY_MAX);
// A cut inside a surrogate pair leaves a lone surrogate that encodeURIComponent rejects.
if (/[\uD800-\uDBFF]$/.test(cut)) cut = cut.slice(0, -1);
return { text: cut.trimEnd(), truncated: true };
}

function markdown(data) {
Expand Down
Loading