Skip to content

Commit

Permalink
Merge branch 'master' into feature/hidden_event_achievement
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras authored Jan 20, 2025
2 parents 9fe0156 + 28fc893 commit 104cbf1
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 5 deletions.
4 changes: 0 additions & 4 deletions app/Policies/NewsPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public function manage(User $user): bool
{
return $user->hasAnyRole([
Role::ADMINISTRATOR,
Role::DEVELOPER,
Role::EVENT_MANAGER,
Role::MODERATOR,
Role::NEWS_MANAGER,
Expand All @@ -39,7 +38,6 @@ public function create(User $user): bool
{
return $user->hasAnyRole([
Role::ADMINISTRATOR,
Role::DEVELOPER,
Role::EVENT_MANAGER,
Role::MODERATOR,
Role::NEWS_MANAGER,
Expand All @@ -51,7 +49,6 @@ public function update(User $user, News $news): bool
{
return $user->hasAnyRole([
Role::ADMINISTRATOR,
Role::DEVELOPER,
Role::EVENT_MANAGER,
Role::MODERATOR,
Role::NEWS_MANAGER,
Expand Down Expand Up @@ -106,7 +103,6 @@ public function pin(User $user, News $news): bool
{
return $user->hasAnyRole([
Role::ADMINISTRATOR,
Role::NEWS_MANAGER,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,71 @@ describe('Util: preProcessShortcodesInBody', () => {
// ASSERT
expect(result).toEqual(input);
});

it('normalizes escaped newlines to actual newlines', () => {
// ARRANGE
const input = 'first line↵\nsecond line';

// ACT
const result = preProcessShortcodesInBody(input);

// ASSERT
expect(result).toEqual('first line\nsecond line');
});

it('handles mixed escaped and actual newlines', () => {
// ARRANGE
const input = 'first line↵\nsecond line\nthird line↵\nfourth line';

// ACT
const result = preProcessShortcodesInBody(input);

// ASSERT
expect(result).toEqual('first line\nsecond line\nthird line\nfourth line');
});

it('normalizes line endings when content includes shortcodes', () => {
// ARRANGE
const input =
'Check out https://retroachievements.org/user/ScottAdams↵\nAnd also↵\nhttps://retroachievements.org/game/1234';

// ACT
const result = preProcessShortcodesInBody(input);

// ASSERT
expect(result).toEqual('Check out [user=ScottAdams]\nAnd also\n[game=1234]');
});

it('handles carriage returns and different line ending styles', () => {
// ARRANGE
const input = 'line1\r\nline2\rline3\nline4';

// ACT
const result = preProcessShortcodesInBody(input);

// ASSERT
expect(result).toEqual('line1\nline2\nline3\nline4');
});

it('preserves whitespace while normalizing line endings', () => {
// ARRANGE
const input = ' indented↵\n still indented ↵\n\n more space ';

// ACT
const result = preProcessShortcodesInBody(input);

// ASSERT
expect(result).toEqual(' indented\n still indented \n\n more space ');
});

it('preserves whitespace while normalizing encoded line endings', () => {
// ARRANGE
const input = ' indented\u21B5\n still indented \u21B5\n\n more space ';

// ACT
const result = preProcessShortcodesInBody(input);

// ASSERT
expect(result).toEqual(' indented\n still indented \n\n more space ');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ const createPatterns = (type: string) => [
];

export function preProcessShortcodesInBody(body: string): string {
let result = body;
// First, normalize any escaped newlines back to actual newlines.
let result = body.replace(/\u21B5\n/g, '\n');

// Then, normalize any remaining line endings.
result = result.replace(/\r\n|\r|\n/g, '\n');

for (const { type, shortcode } of shortcodeTypes) {
const patterns = createPatterns(type);
Expand Down

0 comments on commit 104cbf1

Please sign in to comment.