camilleroux/discourse-affiliate — pull request #1 by Yannshu (2014-11-13 11:16:48+00:00)
Title: Prevent tagging if the url already contains a tag

Hi Camille,

Here are my modifications to prevent url tagging if the url already contains an Amazon affiliate tag.
Modifications have been tested using Rhino in command line (as I was to lazy to install the whole Ruby + Discourse + plugins + ...).

Here is the small piece of code used to perform the tests:
```javascript
testFunc = function(url, expectedResult) {

print("Input url : " + url);
print("Output url : " + addTagToEnd(url));
print("Expected result : " + expectedResult + "\n")
};
```

And here are the tests results:
```
Input url : http://www.google.com
Output url : http://www.google.com
Expected result : no tag added (host isn't an amazon host)

Input url : http://amazon.com
Output url : http://amazon.com/?tag=pragmatentrep-20
Expected result : tag added

Input url : http://www.amazon.com/gp/product/0671027034/ref=s9_psimh_gw_p14_d1_i1?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=03GCW33569B2NMS2NF5N&pf_rd_t=101&pf_rd_p=1688200382&pf_rd_i=507846
Output url : http://www.amazon.com/gp/product/0671027034/ref=s9_psimh_gw_p14_d1_i1?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=03GCW33569B2NMS2NF5N&pf_rd_t=101&pf_rd_p=1688200382&pf_rd_i=507846&tag=pragmatentrep-20
Expected result : tag added

Input url : http://www.amazon.fr/gp/product/0142000280/ref=s9_simh_gw_p14_d1_i3?pf_rd_m=A1X6FK5RDHNB96&pf_rd_s=center-2&pf_rd_r=0M9Y0YVSB61XHBA4Q6YR&pf_rd_t=101&pf_rd_p=455673027&pf_rd_i=405320
Output url : http://www.amazon.fr/gp/product/0142000280/ref=s9_simh_gw_p14_d1_i3?pf_rd_m=A1X6FK5RDHNB96&pf_rd_s=center-2&pf_rd_r=0M9Y0YVSB61XHBA4Q6YR&pf_rd_t=101&pf_rd_p=455673027&pf_rd_i=405320&tag=pragmaticentrepreneurs-21
Expected result : tag added

Input url : http://www.amazon.de/gp/product/B00MWX3IUW/ref=s9_ri_gw_g74_i3/280-6381533-1510131?pf_rd_m=A3JWKAKR8XB7XF&pf_rd_s=center-4&pf_rd_r=12T80R8ECZFE5B83B9BH&pf_rd_t=101&pf_rd_p=475747047&pf_rd_i=301128
Output url : http://www.amazon.de/gp/product/B00MWX3IUW/ref=s9_ri_gw_g74_i3/280-6381533-1510131?pf_rd_m=A3JWKAKR8XB7XF&pf_rd_s=center-4&pf_rd_r=12T80R8ECZFE5B83B9BH&pf_rd_t=101&pf_rd_p=475747047&pf_rd_i=301128
Expected result : no tag added (no tag configured for german host)

Input url : http://www.amazon.com/gp/product/0671027034
Output url : http://www.amazon.com/gp/product/0671027034/?tag=pragmatentrep-20
Expected result : tag added

Input url : http://www.amazon.com/gp/product/0671027034/
Output url : http://www.amazon.com/gp/product/0671027034/?tag=pragmatentrep-20
Expected result : tag added

Input url : http://www.amazon.com/gp/product/0671027034/ref=as_li_tl?ie=UTF8&camp=211189&creative=373489&creativeASIN=0671027034&link_code=as3&tag=yannshu-20&linkId=WB3QDDRNPKIZO2RB
Output url : http://www.amazon.com/gp/product/0671027034/ref=as_li_tl?ie=UTF8&camp=211189&creative=373489&creativeASIN=0671027034&link_code=as3&tag=yannshu-20&linkId=WB3QDDRNPKIZO2RB
Expected result : no tag added (a tag is already present)

Input url : http://www.amazon.com/gp/product/0671027034/ref=as_li_tl?ie=UTF8&camp=211189&creative=373489&creativeASIN=0671027034&link_code=as3&tag=&linkId=WB3QDDRNPKIZO2RB
Output url : http://www.amazon.com/gp/product/0671027034/ref=as_li_tl?ie=UTF8&camp=211189&creative=373489&creativeASIN=0671027034&link_code=as3&tag=pragmatentrep-20&linkId=WB3QDDRNPKIZO2RB
Expected result : tag added (present tag in the url was empty)
```

Let me know what you think about it!

Regards,

Yann