Skip to content

Commit 416a1ca

Browse files
committed
Render /dev/null as the wordmark in commits and replies
1 parent ec7ab94 commit 416a1ca

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎resources/js/components/linkified-text.tsx‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Link } from '@inertiajs/react';
22
import type { ReactNode } from 'react';
3+
import AppWordmark from '@/components/app-wordmark';
34
import { UserPreview } from '@/components/user-preview';
45
import { typedProse } from '@/lib/code';
56
import { shortenUrl } from '@/lib/urls';
@@ -145,6 +146,26 @@ function withPasteis(text: string, pasteisMode: boolean): ReactNode {
145146
);
146147
}
147148

149+
function withWordmarks(text: string, pasteisMode: boolean): ReactNode[] {
150+
return text
151+
.split(
152+
/(?<![\p{L}\p{M}\p{N}_./-])(\/dev\/null)(?![\p{L}\p{M}\p{N}_/-])/u,
153+
)
154+
.map((part, index) =>
155+
index % 2 === 0 ? (
156+
withPasteis(part, pasteisMode)
157+
) : (
158+
<span
159+
key={`wordmark-${index}`}
160+
title={part}
161+
className="font-semibold tracking-tight whitespace-nowrap"
162+
>
163+
<AppWordmark />
164+
</span>
165+
),
166+
);
167+
}
168+
148169
function withMentions(
149170
text: string,
150171
offset: number,
@@ -156,7 +177,7 @@ function withMentions(
156177

157178
for (const match of text.matchAll(mentionPattern)) {
158179
parts.push(
159-
withPasteis(text.slice(position, match.index), pasteisMode),
180+
...withWordmarks(text.slice(position, match.index), pasteisMode),
160181
isStatic ? (
161182
match[0]
162183
) : (
@@ -178,7 +199,7 @@ function withMentions(
178199
position = match.index + match[0].length;
179200
}
180201

181-
parts.push(withPasteis(text.slice(position), pasteisMode));
202+
parts.push(...withWordmarks(text.slice(position), pasteisMode));
182203

183204
return parts;
184205
}

‎tests/Unit/LinkifiedText.test.tsx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,19 @@ for (const body of [
5454
assert.deepEqual(typedLinks(body), []);
5555
});
5656
}
57+
58+
void test('renders /dev/null as the wordmark while keeping its text', () => {
59+
const text = 'piped to /dev/null, then /dev/null. (/dev/null)';
60+
const markup = renderToStaticMarkup(<LinkifiedText text={text} />);
61+
62+
assert.equal(markup.match(/title="\/dev\/null"/g)?.length, 3);
63+
assert.equal(markup.replace(/<[^>]+>/g, ''), text);
64+
});
65+
66+
void test('leaves /dev/null inside longer paths, words, URLs and usernames as text', () => {
67+
const text =
68+
'/dev/nullable /dev/null/log a/dev/null /dev/null_1 /DEV/NULL https://example.com/dev/null @devnull';
69+
const markup = renderToStaticMarkup(<LinkifiedText text={text} />);
70+
71+
assert.ok(!markup.includes('title="/dev/null"'));
72+
});

0 commit comments

Comments
 (0)