mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
fix(tools): bound untrusted display text at output boundaries
This commit is contained in:
1 parent
de2138e84c
commit
586ed4f8ea
9 files changed
+106
-17
No files matched your search
+8
-11
@@ -1,3 +1,4 @@
|
||||
import { normalizeDisplayText } from '../data/displayText.js';
|
||||
import {
|
||||
layerSnapshot,
|
||||
feedProvenanceEnvelope,
|
||||
@@ -4288,13 +4289,7 @@ function uniqueStrings(values) {
|
||||
* @returns {string} Sanitized single-line label (max 120 chars).
|
||||
*/
|
||||
function sanitizeLabel(value) {
|
||||
const text = String(value || '');
|
||||
let out = '';
|
||||
for (const ch of text) {
|
||||
const code = ch.codePointAt(0);
|
||||
out += code < 0x20 || code === 0x7f ? ' ' : ch; // drop control chars incl. newlines
|
||||
}
|
||||
return out.replace(/\s+/g, ' ').trim().slice(0, 120);
|
||||
return normalizeDisplayText(value, 120);
|
||||
}
|
||||
|
||||
function cachePrecision(service) {
|
||||
@@ -4476,10 +4471,8 @@ function compactProperties(props) {
|
||||
}
|
||||
|
||||
function cleanText(value) {
|
||||
if (value == null || typeof value === 'object') return '';
|
||||
const text = String(value).trim();
|
||||
if (!text || text === 'undefined' || text === 'null') return '';
|
||||
return text.length > 180 ? `${text.slice(0, 177)}...` : text;
|
||||
const text = normalizeDisplayText(value);
|
||||
return text === 'undefined' || text === 'null' ? '' : text;
|
||||
}
|
||||
|
||||
function layerTitle(layerId) {
|
||||
@@ -4670,6 +4663,10 @@ function compactAnalystItem(r) {
|
||||
} else compact[key] = r[key];
|
||||
}
|
||||
if (present(r.ageHours)) compact.ageHours = r.ageHours;
|
||||
for (const key of Object.keys(compact)) {
|
||||
if (typeof compact[key] === 'string')
|
||||
compact[key] = normalizeDisplayText(compact[key]);
|
||||
}
|
||||
return compact;
|
||||
}
|
||||
|
||||
|
||||
@@ -3931,3 +3931,16 @@ test('analyst-only lookup distinguishes duplicate names and uses canonical aircr
|
||||
assert.equal(plane.ok, true);
|
||||
assert.equal(plane.latitude, 36, 'canonical ID resolves the current position, not old coordinates');
|
||||
});
|
||||
|
||||
|
||||
test('analyst item display strings are single-line and bounded for voice', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const rows = [{ id: 'stable-id', name: 'Şehir\n' + 'x'.repeat(3000), label: 'Town\tStation', operator: 'City\nPD', lat: 30, lon: -97 }];
|
||||
const { runner } = manifestRunner({ bikeshare: { getStats: () => ({ count: 1, lastUpdate: Date.now() }), getAnalystRecords: () => rows } });
|
||||
const result = await runner('analyst_query', { layers: ['bikeshare'], scope: { kind: 'anywhere' }, limit: 1 });
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.items[0].name.length, 180);
|
||||
assert.equal(result.items[0].label, 'Town Station');
|
||||
assert.equal(result.items[0].id, 'stable-id');
|
||||
for (const value of Object.values(result.items[0])) if (typeof value === 'string') assert.doesNotMatch(value, /[\r\n\t]/);
|
||||
});
|
||||
Reference in new issue
Block a user