Skip to content

Open-source, local-first social media research agent for Instagram, TikTok, and LinkedIn. Jev routes read-only steps; socai CLI captures cited browser evidence.

fix: make quote trimming linear

Asklv0ad56a944f07
diff --git a/src/query.js b/src/query.js
index f477c2b..17b0595 100644
--- a/src/query.js
+++ b/src/query.js
@@ -42,11 +42,16 @@ export function extractSearchQuery(request) {
}
function cleanTopic(value) {
- return value
- .trim()
- .replace(/^["'“‘]+/, "")
- .replace(/["'”’]+$/, "")
+ return trimQuoteEdges(value.trim())
.replace(/\s+please$/i, "")
.replace(/[。.!??]+$/g, "")
.trim();
}
+
+function trimQuoteEdges(value) {
+ let start = 0;
+ let end = value.length;
+ while (start < end && "\"'“‘".includes(value[start])) start += 1;
+ while (end > start && "\"'”’".includes(value[end - 1])) end -= 1;
+ return value.slice(start, end);
+}
diff --git a/test/query.test.js b/test/query.test.js
index 766d600..2ddf6c9 100644
--- a/test/query.test.js
+++ b/test/query.test.js
@@ -39,3 +39,8 @@ test("extractSearchQuery preserves an already literal search term", () => {
assert.equal(extractSearchQuery("instagram marketing tips"), "instagram marketing tips");
assert.equal(extractSearchQuery("mr beast"), "mr beast");
});
+
+test("extractSearchQuery trims long quote runs without changing the topic", () => {
+ const quotes = "\"".repeat(10_000);
+ assert.equal(extractSearchQuery(`search Instagram for ${quotes}AI creators${quotes}`), "AI creators");
+});