google-ads-api 19.0.3-rest-beta → 19.0.4-rest-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/query.js +27 -5
- package/package.json +1 -1
package/build/src/query.js
CHANGED
|
@@ -67,6 +67,31 @@ function buildFromClause(entity) {
|
|
|
67
67
|
}
|
|
68
68
|
return ` ${QueryKeywords.FROM} ${entity}`;
|
|
69
69
|
}
|
|
70
|
+
function formatGaqlString(val) {
|
|
71
|
+
const len = val.length;
|
|
72
|
+
const startsWithSingle = val.startsWith("'");
|
|
73
|
+
const endsWithSingle = val.endsWith("'");
|
|
74
|
+
const startsWithDouble = val.startsWith('"');
|
|
75
|
+
const endsWithDouble = val.endsWith('"');
|
|
76
|
+
// Returns the original string if it seems correctly quoted already.
|
|
77
|
+
if (len >= 2) {
|
|
78
|
+
if (startsWithSingle && endsWithSingle && !val.slice(1, -1).includes("'")) {
|
|
79
|
+
return val;
|
|
80
|
+
}
|
|
81
|
+
if (startsWithDouble && endsWithDouble && !val.slice(1, -1).includes('"')) {
|
|
82
|
+
return val;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Always use double quotes and escape internal double quotes and backslashes
|
|
86
|
+
if (val.includes('"') || val.includes("\\")) {
|
|
87
|
+
const escapedVal = val.replace(/\\/g, "\\\\").replace(/"/g, '\\"'); // Escape backslashes first, then double quotes
|
|
88
|
+
return `"${escapedVal}"`;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// No escaping needed, just wrap in double quotes
|
|
92
|
+
return `"${val}"`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
70
95
|
function validateConstraintKeyAndValue(key, op, val) {
|
|
71
96
|
if (typeof val === "number" || typeof val === "boolean") {
|
|
72
97
|
return { op: "=", val: convertNumericEnumToString(key, val) };
|
|
@@ -75,16 +100,13 @@ function validateConstraintKeyAndValue(key, op, val) {
|
|
|
75
100
|
if (types_1.dateConstants.includes(val)) {
|
|
76
101
|
return { op, val };
|
|
77
102
|
}
|
|
78
|
-
return {
|
|
79
|
-
op: "=",
|
|
80
|
-
val: new RegExp(/^'.*'$|^".*"$/g).test(val) ? val : `"${val}"`,
|
|
81
|
-
}; // must start and end in either single or double quotation marks
|
|
103
|
+
return { op: "=", val: formatGaqlString(val) };
|
|
82
104
|
}
|
|
83
105
|
if (Array.isArray(val)) {
|
|
84
106
|
const stringifiedValue = val
|
|
85
107
|
.map((v) => {
|
|
86
108
|
if (typeof v === "string") {
|
|
87
|
-
return
|
|
109
|
+
return formatGaqlString(v);
|
|
88
110
|
}
|
|
89
111
|
else {
|
|
90
112
|
return convertNumericEnumToString(key, v);
|
package/package.json
CHANGED