24

Im generating URLs for my AdWord campaigns and some campangin names have brackets in them ( ) and [ ] brackets. And a sample url looks likes this

http://www.website.com/?utm_source=google%5BB%2B%5D&utm_medium=cpc&utm_content=google_ad(B)&utm_campaign=product

Is this fine?

0lukasz0
  • 3,155
  • 1
  • 24
  • 40
nasty
  • 6,797
  • 9
  • 37
  • 52
  • 7
    `( )` are called parenthesis. – John Woo Nov 05 '12 at 02:00
  • 8
    @JohnWoo Hey, isn't it still correct to call them brackets? – Alvin Wong Nov 05 '12 at 02:07
  • 6
    @JohnWoo http://en.wikipedia.org/wiki/Bracket – Gabriel Santos Nov 05 '12 at 02:08
  • 4
    It is correct to call `( )`, `[ ]` or `{ }` brackets as they are all included in the bracket family of punctuation marks, per the previously linked documentation (https://en.wikipedia.org/wiki/Bracket). – Luke Sep 01 '17 at 22:25
  • 4
    Being correct is nice, being specific feels better. "Sun is shining" is correct but does not help the question of "Is this fine?" being understood and answered better. – Bahram Ardalan Feb 09 '21 at 15:41
  • 1
    @JohnWoo - the plural is actually "parentheses." This is neither here nor there imo. We all know what the guy is talking about. Let's all treat each other with respect and send good, warm vibes out into the universe. :) – KennethDale1 Mar 25 '22 at 02:35

2 Answers2

35

Parentheses “()” may be used as such in the query part of URL (i.e., the part after “?”). It is allowable, but not necessary, to %-encode them, as “%28” and “%29”.

Brackets “[]” shall be %-encoded, as “%5B” and “%5D”, in the query part.

The sample URL, which is a real URL as www.website.com actually exists (please use www.example.com as a dummy domain name, it is guaranteed to not exist), is thus correctly formed.

The general rules for URL syntax are defined in Internet-standard STD 66, which is currently RFC 3986. Its Appendix A specifies the rules for characters, listing parentheses as belonging to the “sub-delims” group which is allowed without %-encoding in the query part but the brackets as belonging to “gen-delims” which shall be %-encoded.

Alan
  • 1,889
  • 2
  • 18
  • 30
Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390
  • Why is it then that when I post a URL in brackets on forums, the brackets (thankfully) don't get interpreted? Is it a non-standard design choice by the website to reflect the likelihood of posters intending the same as me? – Sridhar Sarnobat Mar 09 '17 at 04:21
  • Yes, it's a non-standard adherence to the RFC. – E.g. I am having the same issue with the `fields=items.view(mini)` param to the API from *Citrix Podio*. They will **not interpret** the parenthesis as such, when they get encoded in the param value; is annoying, given that the standard Javascript class **`URLSearchParams` will encode accordingly by default**. So I have to revert the decoding, manually; that is pretty hacky – Kamafeather Mar 31 '21 at 00:17
3

Oh, it is "fine" (as Kinected also asked: what is fine?) for parenthesis but perhaps not for square brackets. But if you are afraid, always use urlencode for query strings.

<?php
echo "http://www.example.com/index.php?boo=",urlencode("sample(parenthesis)and[square_brackets]");
//http://www.example.com/index.php?boo=sample%28parenthesis%29and%5Bsquare_brackets%5D

Demo: http://codepad.org/ZKaROUr7

Alvin Wong
  • 12,210
  • 5
  • 51
  • 77