Commit 78dba12c authored by Caleb Weeks's avatar Caleb Weeks

removing possibility for repeated selector adds. Fix typo

parent 2b8a941e
......@@ -77,7 +77,7 @@ var SlingConnector = module.exports = function(options){
//need to create copies of the keep alive config (using ...) because that library modifies the options object passed in
this.httpRequestAgent = options.httpRequestAgent || new KeepAliveAgent(options.httpAgentKeepAliveConfig ? {...options.httpAgentKeepAliveConfig} : DefaultKeepAliveConfig);
this.httpsRequestAgent = options.httpsRequestAgent || new KeepAliveAgent.HttpsAgent(options.httpsAgentKeepAliveConfig ? {...options.httpsAgentKeepAliveConfig } : DefaultKeepAliveConfig);
this.hasGetIfExistsCapabililty = options.hasGetIfExistsCapabililty;
this.hasGetIfExistsCapability = options.hasGetIfExistsCapability;
this.useGetIfExistsByDefault = options.useGetIfExistsByDefault;
this.inMemoryCache = options.inMemoryCache;
......@@ -224,9 +224,9 @@ SC.getSling = function(path, options = {}, callback){
// get if exists selector
const useGetIfExists =
this.hasGetIfExistsCapabililty && //is the capability enabled
path.match(/^\/(content|etc)\/.*\.json$/) && // is this request a candidate (anything under content or etc that just ends with .json)
((this.useGetIfExistsByDefault && !options.dontUseGetIfExists) || options.useGetIfExists); //and this request should use
sc_self.hasGetIfExistsCapability && //is the capability enabled
path.match(/^\/?(content|etc)\/.*\.json$/) && // is this request a candidate (anything under content or etc that just ends with .json)
((sc_self.useGetIfExistsByDefault && !options.dontUseGetIfExists) || options.useGetIfExists); //and this request should use
if(useGetIfExists){
//inject as the first selector
path = sc_self.util.addSelector(path, selectors.getIfExists, 'json');
......@@ -420,6 +420,7 @@ SC.getSling = function(path, options = {}, callback){
}
}
catch (e) {
var uri=sc_self.buildUri(path);
obj = {};
err = e;
sc_self.logger.warning("JSON parse error: " + uri + "\n" + e);
......@@ -815,25 +816,31 @@ SC.util.getNonMeta=function(data, keyProperty, iterator){
}
SC.util.addSelector = (path, selector, extensionCheck) => {
//inject as the first selector
if(extensionCheck){
//first split into path parts
let pathParts = path.split("/");
//find the segment that has the indicated extension and modify it
return pathParts.map((segment) => {
if(_.endsWith(segment, extensionCheck)){
let segmentParts = segment.split(".");
segmentParts.splice(1, 0, selector);
segment = segmentParts.join('.');
}
let updatedPath = path;
//don't add if the selector is already there
if(path.indexOf(`.${selector}`) < 0){
//inject as the first selector
if(extensionCheck){
//first split into path parts
let pathParts = path.split("/");
//find the segment that has the indicated extension and modify it
updatedPath = pathParts.map((segment) => {
if(_.endsWith(segment, extensionCheck)){
let segmentParts = segment.split(".");
segmentParts.splice(1, 0, selector);
segment = segmentParts.join('.');
}
return segment;
}).join("/");
}else{
let pathParts = path.split(".");
pathParts.splice(1, 0, selector);
return pathParts.join(".");
return segment;
}).join("/");
}else{
let pathParts = path.split(".");
pathParts.splice(1, 0, selector);
updatedPath = pathParts.join(".");
}
}
return updatedPath;
}
......
......@@ -78,7 +78,7 @@ describe("get-if-exists", () => {
}
test("Call getSling with get-if-exists (default) with no other selectors", async () => {
let clonedSc = sc.clone({useGetIfExistsByDefault: true, hasGetIfExistsCapabililty: true});
let clonedSc = sc.clone({useGetIfExistsByDefault: true, hasGetIfExistsCapability: true});
const validExistingResult = await clonedSc.getSling('/content/getIfExists/exists.json');
......@@ -90,7 +90,7 @@ describe("get-if-exists", () => {
});
test("Call getSling with get-if-exists (default) with number selector", async () => {
let clonedSc = sc.clone({useGetIfExistsByDefault: true, hasGetIfExistsCapabililty: true});
let clonedSc = sc.clone({useGetIfExistsByDefault: true, hasGetIfExistsCapability: true});
const validExistingResult = await clonedSc.getSling('/content/getIfExists/exists.1.json');
......@@ -101,7 +101,7 @@ describe("get-if-exists", () => {
});
test("Call getSling with get-if-exists (default) with text selector", async () => {
let clonedSc = sc.clone({useGetIfExistsByDefault: true, hasGetIfExistsCapabililty: true});
let clonedSc = sc.clone({useGetIfExistsByDefault: true, hasGetIfExistsCapability: true});
const validExistingResult = await clonedSc.getSling('/content/getIfExists/exists.infinity.json');
......@@ -112,7 +112,7 @@ describe("get-if-exists", () => {
});
test("Call getSling with get-if-exists (default) with text and deref selector", async () => {
let clonedSc = sc.clone({useGetIfExistsByDefault: true, hasGetIfExistsCapabililty: true, hasDerefCapability: true});
let clonedSc = sc.clone({useGetIfExistsByDefault: true, hasGetIfExistsCapability: true, hasDerefCapability: true});
const validExistingResult = await clonedSc.getSling('/content/getIfExists/exists.infinity.json', {deref: true});
......@@ -123,7 +123,7 @@ describe("get-if-exists", () => {
});
test("Call getSling with get-if-exists (option) with text and deref selector", async () => {
let clonedSc = sc.clone({hasGetIfExistsCapabililty: true, hasDerefCapability: true});
let clonedSc = sc.clone({hasGetIfExistsCapability: true, hasDerefCapability: true});
const validExistingResult = await clonedSc.getSling('/content/getIfExists/exists.infinity.json', {deref: true, useGetIfExists: true});
......@@ -135,7 +135,7 @@ describe("get-if-exists", () => {
test("Call getSling with get-if-exists (option) against non-existing", async () => {
let clonedSc = sc.clone({hasGetIfExistsCapabililty: true});
let clonedSc = sc.clone({hasGetIfExistsCapability: true});
try{
await clonedSc.getSling('/content/getIfExists/doesnt-exist.json', {useGetIfExists: true})
......@@ -151,7 +151,7 @@ describe("get-if-exists", () => {
test("Call getSling with get-if-exists (option) with invalid response", async () => {
let clonedSc = sc.clone({hasGetIfExistsCapabililty: true});
let clonedSc = sc.clone({hasGetIfExistsCapability: true});
try{
await clonedSc.getSling('/content/getIfExists/invalid-res.json', {useGetIfExists: true})
......@@ -166,7 +166,7 @@ describe("get-if-exists", () => {
});
test("Call getSling with get-if-exists (option) with image path", async () => {
let clonedSc = sc.clone({hasGetIfExistsCapabililty: true});
let clonedSc = sc.clone({hasGetIfExistsCapability: true});
try{
await clonedSc.getSling('/content/dam/something/image.jpg/metadata.3.json', {useGetIfExists: true});
......@@ -181,7 +181,7 @@ describe("get-if-exists", () => {
});
test("Call getSling with get-if-exists (option) with foss-exists", async () => {
let clonedSc = sc.clone({hasGetIfExistsCapabililty: true});
let clonedSc = sc.clone({hasGetIfExistsCapability: true});
try{
await clonedSc.getSling('/content/fshr/pages/en.foss-exists.json', {useGetIfExists: true});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment