diff --git a/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-default/src/main/java/org/xwiki/refactoring/internal/ResourceReferenceRenamer.java b/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-default/src/main/java/org/xwiki/refactoring/internal/ResourceReferenceRenamer.java index 8b2c5222262..8d672d573ef 100644 --- a/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-default/src/main/java/org/xwiki/refactoring/internal/ResourceReferenceRenamer.java +++ b/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-default/src/main/java/org/xwiki/refactoring/internal/ResourceReferenceRenamer.java @@ -59,6 +59,10 @@ public class ResourceReferenceRenamer @Inject private EntityReferenceResolver entityReferenceResolver; + @Inject + @Named("relative") + private EntityReferenceResolver relativeEntityReferenceResolver; + @Inject @Named("compact") private EntityReferenceSerializer compactEntityReferenceSerializer; @@ -206,9 +210,10 @@ private boolean updateAbsoluteResourceReference(ResourceReference resourceRefere private String getNewTargetReference(ResourceReference resourceReference, EntityReference newTargetReference, EntityReference currentReference) { + EntityReference entityReference = + this.relativeEntityReferenceResolver.resolve(resourceReference, null, (Object) null); // If the reference contains the wiki name, then we should keep the absolute serialization. - // TODO: This regex feels really fragile, I'm not sure how we should check presence of a wiki here. - if (resourceReference.getReference().matches("^\\w+:\\w.*$")) { + if (entityReference.extractReference(EntityType.WIKI) != null) { return this.defaultEntityReferenceSerializer.serialize(newTargetReference, currentReference); } else { return this.compactEntityReferenceSerializer.serialize(newTargetReference, currentReference);