Skip to content

Commit f719471

Browse files
committed
XWIKI-22571: Backlinks update changes an absolute reference to the moved page into one relative to the current wiki
* simplify condition by using the relative resource reference resolver
1 parent 17dcd42 commit f719471

File tree

1 file changed

+7
-2
lines changed
  • xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-default/src/main/java/org/xwiki/refactoring/internal

1 file changed

+7
-2
lines changed

xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-default/src/main/java/org/xwiki/refactoring/internal/ResourceReferenceRenamer.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public class ResourceReferenceRenamer
5959
@Inject
6060
private EntityReferenceResolver<ResourceReference> entityReferenceResolver;
6161

62+
@Inject
63+
@Named("relative")
64+
private EntityReferenceResolver<ResourceReference> relativeEntityReferenceResolver;
65+
6266
@Inject
6367
@Named("compact")
6468
private EntityReferenceSerializer<String> compactEntityReferenceSerializer;
@@ -206,9 +210,10 @@ private boolean updateAbsoluteResourceReference(ResourceReference resourceRefere
206210
private String getNewTargetReference(ResourceReference resourceReference, EntityReference newTargetReference,
207211
EntityReference currentReference)
208212
{
213+
EntityReference entityReference =
214+
this.relativeEntityReferenceResolver.resolve(resourceReference, null, (Object) null);
209215
// If the reference contains the wiki name, then we should keep the absolute serialization.
210-
// TODO: This regex feels really fragile, I'm not sure how we should check presence of a wiki here.
211-
if (resourceReference.getReference().matches("^\\w+:\\w.*$")) {
216+
if (entityReference.extractReference(EntityType.WIKI) != null) {
212217
return this.defaultEntityReferenceSerializer.serialize(newTargetReference, currentReference);
213218
} else {
214219
return this.compactEntityReferenceSerializer.serialize(newTargetReference, currentReference);

0 commit comments

Comments
 (0)