Skip to content

Commit

Permalink
fix(agent): ensure algolia agent is not duplicated by successive calls
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrutjes authored and vvo committed Jan 4, 2017
1 parent fa1d10f commit 77b9762
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/AlgoliaSearchCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

/*
Expand Down
4 changes: 4 additions & 0 deletions test/spec/common/client/addAlgoliaAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 77b9762

Please sign in to comment.