-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: thumbnail generation for URI string containing spaces (#6698)
#### What type of PR is this? /kind improvement /area core /milestone 2.20.x #### What this PR does / why we need it: 修复文章封面图链接包含空格时主题端会因为生成缩略图错误而无法访问的问题 这是由于 URI string 中包含空格无法创建 URI 对象,目前将忽略这种非法参数,如果生成失败则直接返回原始 URI string #### Which issue(s) this PR fixes: Fixes #6690 #### Does this PR introduce a user-facing change? ```release-note 修复文章封面图链接包含空格时主题端会因为生成缩略图错误而无法访问的问题 ```
- Loading branch information
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
application/src/test/java/run/halo/app/theme/finders/impl/ThumbnailFinderImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package run.halo.app.theme.finders.impl; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.net.URI; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import reactor.core.publisher.Mono; | ||
import reactor.test.StepVerifier; | ||
import run.halo.app.core.attachment.ThumbnailService; | ||
|
||
/** | ||
* Tests for {@link ThumbnailFinderImpl}. | ||
* | ||
* @author guqing | ||
* @since 2.20.0 | ||
*/ | ||
@ExtendWith(MockitoExtension.class) | ||
class ThumbnailFinderImplTest { | ||
|
||
@Mock | ||
ThumbnailService thumbnailService; | ||
|
||
@InjectMocks | ||
ThumbnailFinderImpl thumbnailFinder; | ||
|
||
@Test | ||
void shouldNotGenWhenUriIsInvalid() { | ||
thumbnailFinder.gen("invalid uri", "l") | ||
.as(StepVerifier::create) | ||
.expectNext("invalid uri") | ||
.verifyComplete(); | ||
|
||
verify(thumbnailService, times(0)).generate(any(), any()); | ||
} | ||
|
||
@Test | ||
void shouldGenWhenUriIsValid() { | ||
when(thumbnailService.generate(any(), any())) | ||
.thenReturn(Mono.just(URI.create("/test-thumb.jpg"))); | ||
thumbnailFinder.gen("/test.jpg", "l") | ||
.as(StepVerifier::create) | ||
.expectNext("/test-thumb.jpg") | ||
.verifyComplete(); | ||
|
||
verify(thumbnailService).generate(any(), any()); | ||
} | ||
} |