-
Notifications
You must be signed in to change notification settings - Fork 732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#663 canonical url fix #1344
base: main
Are you sure you want to change the base?
#663 canonical url fix #1344
Conversation
rsonth
commented
Jan 15, 2021
Q | A |
---|---|
Fixed Issues? | ` Canonical url fix |
Patch: Bug Fix? | #663 |
Minor: New Feature? | Yes |
Major: Breaking Change? | No |
Tests Added + Pass? | Yes |
Documentation Provided | Yes |
Any Dependency Changes? | No |
License | Apache License, Version 2.0 |
Codecov Report
@@ Coverage Diff @@
## development #1344 +/- ##
=================================================
- Coverage 84.92% 84.90% -0.02%
- Complexity 1802 1805 +3
=================================================
Files 169 169
Lines 5080 5089 +9
Branches 801 803 +2
=================================================
+ Hits 4314 4321 +7
Misses 304 304
- Partials 462 464 +2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a property that should be inherited and not authored on each page. I'm wondering if we shouldn't use a context-aware configuration for storing it. @gabrielwalt , WDYT?
jcr:primaryType="nt:unstructured" | ||
cq-msm-lockable="sling:alias"/> | ||
</alias> | ||
<canonical |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of copy-pasting the entire tab we could just append the field (using ResourceMerger)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes has been taken care as suggested using resource merge. Please review the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vladbailescu Did you get a chance to review the changes? These changes taken care upon your review comments?
if (currentPage != null) { | ||
String authoredCanonicalURL = pageProperties.get(CANONICAL_URL, String.class); | ||
PageManager pageManager = currentPage.getPageManager(); | ||
if (pageManager != null && pageManager.getPage(authoredCanonicalURL)!=null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add proper spacing on this line and the line bellow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been taken care
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vladbailescu Did you get a chance to review the changes? These changes taken care upon your review comments?
@@ -148,6 +150,8 @@ | |||
private String[] clientLibCategoriesJsHead; | |||
|
|||
private List<HtmlPageItem> htmlPageItems; | |||
|
|||
public static final String CANONICAL_URL = "canonical"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constants should be defined in the model interface and follow the name convention there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been taken care
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vladbailescu Did you get a chance to review the changes? These changes taken care upon your review comments?
if (currentPage != null) { | ||
String authoredCanonicalURL = pageProperties.get(CANONICAL_URL, String.class); | ||
PageManager pageManager = currentPage.getPageManager(); | ||
if (pageManager != null && pageManager.getPage(authoredCanonicalURL)!=null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure Page#getPageManager()
cannot return null,
Also, the canonical page is resolved twice via PageManager#getPage()
.
Once to assert the page exists and perform the null check, a second time to actually use it to craft the URL.
Although we can be pretty certain that the second call won't return null, there is no guarantee.
An alternative would be something like
@Override
public String getCanonicalURL() {
if (currentPage != null) {
String authoredCanonicalURL = pageProperties.get(CANONICAL_URL, String.class)
PageManager pageManager = currentPage.getPageManager();
return Optional.ofNullable(authoredCanonicalURL)
.map(pageManager::getPage)
.map(p -> Utils.getURL(request, pageManager, p))
.orElse(authoredCanonicalURL);
}
return null
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made changes as suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vladbailescu @ky940819 Did you get a chance to review the changes? These changes taken care upon your review comments?
@@ -161,4 +161,18 @@ void testHtmlPageItemsConfig() { | |||
assertNotNull(page.getHtmlPageItems()); | |||
assertEquals(3, page.getHtmlPageItems().size(), "Unexpected number of HTML page items"); | |||
} | |||
|
|||
@Test | |||
void testgetCanonicalURL_External() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The not null assertion isn't enough to validate that it is functioning properly.
Need to ensure that the value returned is the value expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required changes have been taken care.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vladbailescu @ky940819 Did you get a chance to review the changes? These changes taken care upon your review comments?
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vladbailescu @ky940819 Did you get a chance to review the changes?