Author Topic: Escaping left and right brackets in forum posts  (Read 580 times)

0 Members and 1 Guest are viewing this topic.

Offline ledtesterTopic starter

  • Super Contributor
  • ***
  • Posts: 3111
  • Country: us
Escaping left and right brackets in forum posts
« on: May 23, 2024, 02:24:42 pm »
Just sharing a method I learned to "escape" left and right square brackets in BBcode (the markup language used here on the forum) - that is, to insert BBcode tags into your post without having them interpreted as tags.

Most of the time you can use the [code] tag, e.g.:

Quote
To insert a link use the url tag, for example:
Code: [Select]
[url=https://cnn.com]This is CNN[/url]
will produce the link: This is CNN

But what if you want to show how to use the [code] tag? Using:

Quote
[code]
To format code in a post, use a [code] ... [/code] block.
[/code]

doesn't work because code blocks do not nest - the first end code tag will terminate the outer code block.

Or what if you want the tags to appear inline, e.g.

Quote
using [s]some text[/s] will make "some text" appear with a line through it, e.g. some text

The trick is to use a style tag to break-up the tag you want to insert literally, e.g. to insert [TAG] use:

Code: [Select]
[color=black][TAG[/color][color=black]][/color]

Besides the [color] tag other style tags will also work for this purpose, e.g. [b], [i], [u], [s], [tt], [font], [size]. Of course, whatever style tag you use will affect the enclosed text.
 

Online magic

  • Super Contributor
  • ***
  • Posts: 6922
  • Country: pl
Re: Escaping left and right brackets in forum posts
« Reply #1 on: May 23, 2024, 03:44:55 pm »
Interesting question.

Not sure if there is any "official" solution, but I came up with a simpler version of your hack:
Code: [Select]
[[b][/b]code][code]
 
The following users thanked this post: ledtester, abeyer

Online tooki

  • Super Contributor
  • ***
  • Posts: 12041
  • Country: ch
Re: Escaping left and right brackets in forum posts
« Reply #2 on: May 24, 2024, 10:37:25 am »
Interesting question.

Not sure if there is any "official" solution, but I came up with a simpler version of your hack:
Code: [Select]
[[b][/b]code][code]
Yep. I also use this exact trick to break up unwanted smileys, like 8) (which otherwise becomes 8) — this has to be the most poorly thought-out smiley shortcut ever conceived).
 

Offline Brumby

  • Supporter
  • ****
  • Posts: 12352
  • Country: au
Re: Escaping left and right brackets in forum posts
« Reply #3 on: May 24, 2024, 10:45:23 am »
Yeah, I've used this trick for years, usually with the colour - but you don't have to do it to the trailing bracket

[color=black][TAG[/color]]  =  [TAG]
 

Offline tom66

  • Super Contributor
  • ***
  • Posts: 6817
  • Country: gb
  • Electronics Hobbyist & FPGA/Embedded Systems EE
Re: Escaping left and right brackets in forum posts
« Reply #4 on: May 24, 2024, 11:48:39 am »
You can also use similar characters, though they won't copy-and-paste correctly.

For instance, this is an example using с (Cyrillic 'Es'), which is not c (Latin 'c').

[сode]Testing[/сode]

This has security implications for creating similar-appearing text that has different binary signatures, think web URLs.  Imagine:  paypal.com vs рayрal.com.  These are different, but only in Unicode land.  Thankfully, there are steps taken to reduce the chance of this being a practical attack in the real world. 
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf