Skip to content

Commit

Permalink
XWIKI-22571: Backlinks update changes an absolute reference to the mo…
Browse files Browse the repository at this point in the history
…ved page into one relative to the current wiki

  * simplify condition by using the relative resource reference resolver
  • Loading branch information
surli committed Nov 22, 2024
1 parent 17dcd42 commit f719471
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public class ResourceReferenceRenamer
@Inject
private EntityReferenceResolver<ResourceReference> entityReferenceResolver;

@Inject
@Named("relative")
private EntityReferenceResolver<ResourceReference> relativeEntityReferenceResolver;

@Inject
@Named("compact")
private EntityReferenceSerializer<String> compactEntityReferenceSerializer;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f719471

Please sign in to comment.