From 77b97629dbc692401c07b0d03854d6a93c57022c Mon Sep 17 00:00:00 2001 From: Raymond Rutjes Date: Wed, 4 Jan 2017 17:33:33 +0100 Subject: [PATCH] fix(agent): ensure algolia agent is not duplicated by successive calls --- src/AlgoliaSearchCore.js | 4 +++- test/spec/common/client/addAlgoliaAgent.js | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/AlgoliaSearchCore.js b/src/AlgoliaSearchCore.js index 3a42d03f4..e51106c4a 100644 --- a/src/AlgoliaSearchCore.js +++ b/src/AlgoliaSearchCore.js @@ -154,7 +154,9 @@ AlgoliaSearchCore.prototype.setExtraHeader = function(name, value) { * @param algoliaAgent the agent to add */ AlgoliaSearchCore.prototype.addAlgoliaAgent = function(algoliaAgent) { - this._ua += ';' + algoliaAgent; + if (this._ua.indexOf(';' + algoliaAgent) === -1) { + this._ua += ';' + algoliaAgent; + } }; /* diff --git a/test/spec/common/client/addAlgoliaAgent.js b/test/spec/common/client/addAlgoliaAgent.js index c75dfd9a8..96ca8b53b 100644 --- a/test/spec/common/client/addAlgoliaAgent.js +++ b/test/spec/common/client/addAlgoliaAgent.js @@ -16,6 +16,10 @@ test('client.addAlgoliaAgent(algoliaAgent)', function(t) { var index = fixture.index; client.addAlgoliaAgent('And some other incredible agent'); + + // Ensure we de-duplicate by re-adding the same agent a second time. + client.addAlgoliaAgent('And some other incredible agent'); + index.search('algolia agent'); var expectedAgent = fixture.algoliasearch.ua + ';And some other incredible agent';