From 571dbf5bd65e7d0e261562ff3da3b393f27f27b6 Mon Sep 17 00:00:00 2001
From: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com>
Date: Thu, 30 Nov 2023 13:05:00 +0530
Subject: [PATCH] fix: encode &, < and > to html counterparts in adobe
analytics (#2854)
* fix: encode &, < and > to html counterparts in adobe
* fix: use encodeurl on url valuez
---
.../destinations/adobe_analytics/transform.js | 3 +-
src/v0/destinations/adobe_analytics/utils.js | 26 ++++++++--
.../adobe_analytics/processor/data.ts | 47 ++++++++++---------
3 files changed, 49 insertions(+), 27 deletions(-)
diff --git a/src/v0/destinations/adobe_analytics/transform.js b/src/v0/destinations/adobe_analytics/transform.js
index a805e379ff..8bac0edd70 100644
--- a/src/v0/destinations/adobe_analytics/transform.js
+++ b/src/v0/destinations/adobe_analytics/transform.js
@@ -76,6 +76,7 @@ const responseBuilderSimple = async (message, destinationConfig, basicPayload) =
}
payload.linkURL =
adobeIntegrationsObject?.linkURL || context?.page?.url || 'No linkURL provided';
+ payload.linkURL = encodeURI(payload.linkURL);
}
// handle hier
if (overrideHiers) {
@@ -97,7 +98,7 @@ const responseBuilderSimple = async (message, destinationConfig, basicPayload) =
const propertiesPageUrl = properties?.pageUrl;
const pageUrl = contextPageUrl || propertiesPageUrl;
if (isDefinedAndNotNullAndNotEmpty(pageUrl)) {
- payload.pageUrl = pageUrl;
+ payload.pageUrl = encodeURI(pageUrl);
}
if (trackPageName) {
// better handling possible here, both error and implementation wise
diff --git a/src/v0/destinations/adobe_analytics/utils.js b/src/v0/destinations/adobe_analytics/utils.js
index cbd4f51c23..bcb138d77b 100644
--- a/src/v0/destinations/adobe_analytics/utils.js
+++ b/src/v0/destinations/adobe_analytics/utils.js
@@ -75,6 +75,25 @@ function handleContextData(payload, destinationConfig, message) {
return payload;
}
+/**
+ * This function is used for replacing '&', '<' and '>' with their respective HTML entities
+ * @param {*} inputString
+ * @returns string with HTML entities replaced
+ *
+ */
+
+function escapeToHTML(inputString) {
+ return inputString.replace(
+ /[&<>]/g,
+ (match) =>
+ ({
+ '&': '&',
+ '<': '<',
+ '>': '>',
+ }[match]),
+ );
+}
+
/**
* This function is used for populating the eVars and hVars in the payload
* @param {*} destVarMapping
@@ -90,16 +109,16 @@ function rudderPropToDestMap(destVarMapping, message, payload, destVarStrPrefix)
let val = get(message, `properties.${key}`);
if (isDefinedAndNotNull(val)) {
const destVarKey = destVarStrPrefix + destVarMapping[key];
- mappedVar[destVarKey] = val;
+ mappedVar[destVarKey] = escapeToHTML(val);
} else {
SOURCE_KEYS.some((sourceKey) => {
val = getMappingFieldValueFormMessage(message, sourceKey, key);
if (isDefinedAndNotNull(val)) {
- mappedVar[`${destVarStrPrefix}${[destVarMapping[key]]}`] = val;
+ mappedVar[`${destVarStrPrefix}${[destVarMapping[key]]}`] = escapeToHTML(val);
} else {
val = getValueByPath(message, key);
if (isDefinedAndNotNull(val)) {
- mappedVar[`${destVarStrPrefix}${[destVarMapping[key]]}`] = val;
+ mappedVar[`${destVarStrPrefix}${[destVarMapping[key]]}`] = escapeToHTML(val);
}
}
});
@@ -200,4 +219,5 @@ module.exports = {
handleList,
handleCustomProperties,
stringifyValueAndJoinWithDelimiter,
+ escapeToHTML,
};
diff --git a/test/integrations/destinations/adobe_analytics/processor/data.ts b/test/integrations/destinations/adobe_analytics/processor/data.ts
index 378523ac3c..690639c057 100644
--- a/test/integrations/destinations/adobe_analytics/processor/data.ts
+++ b/test/integrations/destinations/adobe_analytics/processor/data.ts
@@ -1,7 +1,7 @@
export const data = [
{
name: 'adobe_analytics',
- description: 'Test 0',
+ description: 'Test 0: [ECom]: Product Viewed',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -31,7 +31,7 @@ export const data = [
referring_domain: 'google.com',
search: 'estore bestseller',
title: 'The best sellers offered by EStore',
- url: 'https://www.estore.com/best-seller/1',
+ url: 'https://www.estore.com/best-seller/News & Sports?ik=123&ij=456',
name: 'Best Seller',
},
screen: {
@@ -61,7 +61,7 @@ export const data = [
coupon: 'DISC21',
currency: 'USD',
position: 1,
- url: 'https://www.website.com/product/path',
+ url: 'https://www.website.com/product/path?ik=123&ij=456',
image_url: 'https://www.website.com/product/path.png',
currencyMerch: 25,
addressMerch: 'Delhi',
@@ -170,7 +170,7 @@ export const data = [
JSON_ARRAY: {},
XML: {
payload:
- '17941080sales campaignwebUSD127.0.0.1en-USDalvik/2.1.0 (Linux; U; Android 9; Android SDK built for x86 Build/PSR1.180720.075)https://www.google.com/search?q=estore+bestsellert01t02roottval001Kolkata9935400932RudderLabs JavaScript SDKr15,faze90Rciaz,hummer,tharhttps://www.estore.com/best-seller/1Best Sellercustompropval1custompropval22020-01-09T10:01:53.558Zmktcloudid001prodViewGames;Game;11;148.39footlockerrudderstackpoc',
+ '17941080sales campaignwebUSD127.0.0.1en-USDalvik/2.1.0 (Linux; U; Android 9; Android SDK built for x86 Build/PSR1.180720.075)https://www.google.com/search?q=estore+bestsellert01t02roottval001Kolkata9935400932RudderLabs JavaScript SDKr15,faze90Rciaz,hummer,tharhttps://www.estore.com/best-seller/News%20&%20Sports?ik=123&ij=456Best Sellercustompropval1custompropval22020-01-09T10:01:53.558Zmktcloudid001prodViewGames;Game;11;148.39footlockerrudderstackpoc',
},
FORM: {},
},
@@ -185,7 +185,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 1',
+ description: 'Test 1: [ECom]: Product Added',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -356,7 +356,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 2',
+ description: 'Test 2: [ECom]: Product Removed',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -527,7 +527,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 3',
+ description: 'Test 3: [ECom]: Cart Viewed',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -708,7 +708,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 4',
+ description: 'Test 4: [ECom]: Checkout started',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -896,7 +896,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 5',
+ description: 'Test 5: [ECom]: Order Completed',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -1085,7 +1085,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 6',
+ description: 'Test 6: Cart Opened',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -1265,7 +1265,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 7',
+ description: 'Test 7: [Custom] Watched Video',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -1285,7 +1285,7 @@ export const data = [
term: 'event data',
content: 'Make sense of the modern data stack',
},
- library: { name: 'RudderLabs JavaScript SDK', version: '2.9.1' },
+ library: { name: 'RudderLabs JavaScript SDK ', version: '2.9.1' },
locale: 'en-US',
page: {
path: '/best-seller/1',
@@ -1311,7 +1311,7 @@ export const data = [
traits: { roott01: 'roottval001' },
event: 'Watched Video',
integrations: { All: true },
- properties: { plan: 'growth', video: 'TEDxGROWTH' },
+ properties: { plan: 'growth', video: 'TEDxGROWTH&MARKETING' },
originalTimestamp: '2020-01-09T10:01:53.558Z',
type: 'track',
sentAt: '2020-01-09T10:02:03.257Z',
@@ -1412,7 +1412,7 @@ export const data = [
JSON_ARRAY: {},
XML: {
payload:
- '17941080sales campaignweb127.0.0.1en-USDalvik/2.1.0 (Linux; U; Android 9; Android SDK built for x86 Build/PSR1.180720.075)https://www.google.com/search?q=estore+bestsellerroottval001RudderLabs JavaScript SDKTEDxGROWTHoWatched Videohttps://www.estore.com/best-seller/1growth2020-01-09T10:01:53.558Zmktcloudid001event1footlockerrudderstackpoc',
+ '17941080sales campaignweb127.0.0.1en-USDalvik/2.1.0 (Linux; U; Android 9; Android SDK built for x86 Build/PSR1.180720.075)https://www.google.com/search?q=estore+bestsellerroottval001RudderLabs JavaScript SDK <Custom>TEDxGROWTH&MARKETINGoWatched Videohttps://www.estore.com/best-seller/1growth2020-01-09T10:01:53.558Zmktcloudid001event1footlockerrudderstackpoc',
},
FORM: {},
},
@@ -1427,7 +1427,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 8',
+ description: 'Test 8: Common Page Call',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -1597,7 +1597,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 9',
+ description: 'Test 9: Currency test event',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -1789,7 +1789,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 10',
+ description: 'Test 10: Override feature test',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -1988,7 +1988,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 11',
+ description: 'Test 11: Override hiers test',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -2188,7 +2188,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 12',
+ description: 'Test 12: product level eVaR',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -2390,7 +2390,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 13',
+ description: 'Test 13: [ERROR]: Invalid message type: Identify',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -2523,7 +2523,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 14',
+ description: 'Test 14: [ERROR]: Message Type is not present.',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -2697,7 +2697,8 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 15',
+ description:
+ 'Test 15: [ERROR]: The event is not a supported ECOM event or a mapped custom event.',
feature: 'processor',
module: 'destination',
version: 'v0',
@@ -2872,7 +2873,7 @@ export const data = [
},
{
name: 'adobe_analytics',
- description: 'Test 16',
+ description: 'Test 16: Test overrideEventName property',
feature: 'processor',
module: 'destination',
version: 'v0',