Bare-bones random quote machine, and a problem with tweeting quotes with semi-colons

Bare-bones random quote machine, and a problem with tweeting quotes with semi-colons
0.0 0

#1

Hello All!

I created a very bare-bones random quote machine. https://codepen.io/megthekiwi/full/qrGKYZ/

It uses the Random Famous Quotes API available thru MashApe.

One thing I noticed is that if the quote contains a semicolon, the entire quote gets “cut-off” at that semi-colon when you try to tweet it.

For example, take this quote:

When one person suffers from a delusion it is called insanity; when many people suffer from a delusion it is called religion. - Robert Pirsig

The JSON returned from the API looks like this:
Object {
author: “Robert Pirsig”,
category: “Famous”,
quote: “When one person suffers from a delusion it is called insanity; when many people suffer from a delusion it is called religion.”
}

I set a variable called quoteString like this:

quoteString = data.quote + " - "+ data.author;

It displays correctly on the webpage itself, but when I hit the “Tweet It” button, the quote gets cut off at the semicolon. Displaying just…

“When one person suffers from a delusion it is called insanity”
… as what you can tweet.

I’m going to investigate different ways to build the tweet button such that the whole quote gets passed even when it has a semicolon. If anyone has some thoughts for me, please pass it along. :slight_smile:


#2

Hello there!

I’m not exactly sure what the technical terms are but. after a quick Google (and remembering that space becomes %20 in a URL), I think it has something to do with URL encoding. If you replace ; with %3B then quotes with ; will parse properly (tested on CodePen).

I hope that helps! :slight_smile: