Skip to content
Draft
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
6 changes: 5 additions & 1 deletion lib/Service/ColumnTypes/TextLinkBusiness.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,17 @@ public function validateValue(mixed $value, Column $column, string $userId, int
}
}

/**
* Whether the scheme is http or https. Schemes compare without case, as RFC 3986
* defines them.
*/
private function isValidUrlProtocol(string $url): bool {
$parsed = parse_url($url);

if ($parsed === false || !isset($parsed['scheme'])) {
return false;
}

return in_array($parsed['scheme'], self::ALLOWED_PROTOCOLS, true);
return in_array(strtolower($parsed['scheme']), self::ALLOWED_PROTOCOLS, true);
}
}
3 changes: 3 additions & 0 deletions lib/Service/GridWidgetTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ public function readWidget(int $index, mixed $widget): WidgetInput {
throw new BadRequestError('The id of widget ' . $index . ' must be a number.');
}
$icon = $widget['icon'] ?? null;
if (is_string($icon)) {
$icon = TextHelper::trim($icon);
}
if ($icon !== null && (!is_string($icon) || ($icon !== '' && !IconHelper::isValid($icon)))) {
throw new BadRequestError('The icon of widget ' . $index . ' must be the name of an icon.');
}
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/Service/ColumnTypes/TextLinkBusinessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ public function testParseValue() {
]), $column));
}

public function testALinkWithAnUpperCaseSchemeIsValid(): void {
$this->textLinkBusiness->validateValue(json_encode([
'title' => 'Test link',
'value' => 'HTTPS://nextcloud.com',
'providerId' => 'url',
]), $this->column, 'userId', 1, null);
$this->addToAssertionCount(1);
}

public function testValidateValue() {
// Assert that no exception is thrown for valid values
try {
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/Service/GridWidgetTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,23 @@ public function testAWidgetIsReadWithEveryField(): void {
]);
}

public static function icons(): array {
return [
'trimmed' => [' star ', 'star'],
'no-break and zero-width spaces' => ["\u{00A0}star\u{200B}", 'star'],
'only blanks' => ["\u{00A0} ", null],
];
}

/**
* @dataProvider icons
*/
public function testTheIconOfAWidgetIsTrimmed(string $icon, ?string $expected): void {
$widget = $this->types->readWidget(0, ['type' => 'text', 'icon' => $icon, 'gridX' => 0, 'gridY' => 0, 'gridWidth' => 6, 'gridHeight' => 2]);

$this->assertSame($expected, $widget->icon);
}

public static function unreadableWidgets(): array {
$widget = ['type' => 'text', 'gridX' => 0, 'gridY' => 0, 'gridWidth' => 6, 'gridHeight' => 2];
return [
Expand Down
Loading