mirror of https://github.com/halo-dev/halo
Fix the problem of generating permalink due to special filename (#2462)
#### What type of PR is this? /kind bug /area core /milestone 2.0 #### What this PR does / why we need it: Encode path of attachment permalink instead of using URI#resolve methods directly. #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2408 #### Special notes for reviewers Steps to test: 1. Create a file with special name, e.g.: `hello world.txt` 2. Upload the file and see the permalink #### Does this PR introduce a user-facing change? ```release-note None ```pull/2466/head
parent
02cc2fa7be
commit
1da89f04e2
|
@ -72,3 +72,4 @@ application-local.properties
|
|||
|
||||
### Zip file for test
|
||||
!src/test/resources/themes/*.zip
|
||||
src/main/resources/console/
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package run.halo.app.core.extension.reconciler.attachment;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.pf4j.PluginManager;
|
||||
import org.springframework.web.util.UriUtils;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import run.halo.app.core.extension.attachment.Attachment;
|
||||
|
@ -63,10 +67,8 @@ public class AttachmentReconciler implements Reconciler<Request> {
|
|||
var localRelativePath = annotations.get(Constant.LOCAL_REL_PATH_ANNO_KEY);
|
||||
if (localRelativePath != null) {
|
||||
// TODO Add router function here.
|
||||
permalink = externalUrl.get()
|
||||
.resolve("/upload/" + localRelativePath)
|
||||
.normalize()
|
||||
.toASCIIString();
|
||||
var encodedPath = UriUtils.encodePath("/upload/" + localRelativePath, UTF_8);
|
||||
permalink = externalUrl.get().resolve(encodedPath).normalize().toString();
|
||||
} else {
|
||||
var externalLink = annotations.get(Constant.EXTERNAL_LINK_ANNO_KEY);
|
||||
if (externalLink != null) {
|
||||
|
@ -79,17 +81,23 @@ public class AttachmentReconciler implements Reconciler<Request> {
|
|||
var status = attachment.getStatus();
|
||||
if (status == null) {
|
||||
status = new AttachmentStatus();
|
||||
attachment.setStatus(status);
|
||||
}
|
||||
status.setPermalink(permalink);
|
||||
}
|
||||
}
|
||||
updateStatus(request.name(), attachment.getStatus());
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
// update status
|
||||
void updateStatus(String attachmentName, AttachmentStatus status) {
|
||||
client.fetch(Attachment.class, attachmentName)
|
||||
.filter(attachment -> !Objects.deepEquals(attachment.getStatus(), status))
|
||||
.ifPresent(attachment -> {
|
||||
attachment.setStatus(status);
|
||||
client.update(attachment);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
void removeFinalizer(String attachmentName) {
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package run.halo.app.core.extension.endpoint;
|
||||
|
||||
class AttachmentEndpointTest {
|
||||
|
||||
}
|
Loading…
Reference in New Issue