Tinderbox Forum

Escape quotes in action code

I’m trying to escape some quotes in action code.

The Action Code:
$TBXRelatedLessonHTML(source)=$TBXRelatedLessonHTML(source)+"<a href="+$ForumPostURL(destination)+">"+$Name(destination)+"</a>";

The Result:
<a href=;http://forum.eastgate.com/t/tinderbox-training-video-daily-journal-time-tracking-project-management-part-1/4153;>;Tinderbox Training Video - Daily Journal Time Tracking Project Management Part 1;</a>

I am getting semicolons, ; , where there should be quotes, ", for the HTML to be properly formatted.

Does anyone have a clue how to fix this?

Please excuse but I added some mark-up so the code you posted could be read properly without re-formatting by the forum software.

This is quite simple. You want to delimit a string in action code that needs to include double (straight) quotes. Action code allows use of both single and double straight quotes as long as properly paired and nested. By general convention double-quotes are used to delimit strings in action code but either form may be used, thus:

"It was a 'crazed' objection."
or
'He said "Hello", I think.'

in the first case it is double enclosing (one or more) single quotes. Vice-versa in the second.

I think your original code should be:

$TBXRelatedLessonHTML(source)=$TBXRelatedLessonHTML(source)+'<a href="'+$ForumPostURL(destination)+'">'+$Name(destination)+"</a>";

In the last part with the closing tag, notice I used double quotes as no quotes needed nesting. This should you can mix both types within an expression. If the contents of the string needed to use both single and double quotes, break the string into parts, so as doubles enclose singles and vice-versa. If both the previous examples were one string:

"It was a 'crazed' objection. He said "+' "Hello", '+"I think."

Does that help?

Thanks, I’d tried that, but I can’t figure out what I’m doing wrong. My link code is returning this:

<a href="";http://forum.eastgate.com/t/tinderbox-training-video-daily-journal-time-tracking-project-management-part-1/4153;">";Tinderbox Training Video - Daily Journal Time Tracking Project Management Part 1;</a><br>

It is putting in semicolons and an extra quote.

Can you take a look? TBX - L LInk Action Code WIP.tbx (179.3 KB)

What is the literal value of$TBXRelatedLessonHTML(source). The semi-colons are I think a little-seen protective measure when Tinderbox is fed bad action code.

I’ve hunch—I can’t find sample $ForumPostURL is the doc you posted—but I made a stamp:

$Text='<a href="'+$ForumPostURL+'">'+$MyString+"</a><br>";

In a code note, I set:
$ForumPostURL: http://forum.eastgate.com/t/tinderbox-training-video-daily-journal-time-tracking-project-management-part-1/4153
and
$MyString: Tinderbox Training Video - Daily Journal Time Tracking Project Management Part 1

The stamp output gives:

<a href="http://forum.eastgate.com/t/tinderbox-training-video-daily-journal-time-tracking-project-management-part-1/4153">Tinderbox Training Video - Daily Journal Time Tracking Project Management Part 1</a><br>

i.e. what we expect.

The only explanation I can think of is you ware pasting the HTML of the link i.e. a string such as the stamp above creates into $ForumPostURL, instead of just the URL itself. Thus you are unintentionally trying to insert an HTML-marked-up link (i.e. URL and anchor) into the href attribute of an HTML link. The resulting nested link code gives poor Tinderbox a headache and it copes as best it can.

The literal value starts out as "" but when you have multiple related lessons then the order of that action code trips the security parameter.

I’ve solved the problem by performing the link generation first and then pasting back in the existing code.

$TBXRelatedLesson(source)=$TBXRelatedLesson(source)+$Name(destination);
$TBXRelatedLessonHTML(source)='<a href="'+$ForumPostURL(destination)+'">'+$Name(destination)+"</a><br>"+$TBXRelatedLessonHTML(source);

Now works great:
image

FWIW, I’ve always found TextSoap is a good option for fixing quotemark issues.

I’m not sure I follow (not that it matters!). If I compare your original and last code the only different seems to be correct nesting/delimiting of quotes.

Nope…the difference is the placement of +$TBXRelatedLessonHTML(source) If I put it at the beginning of the string it triggers the security measure as there could be HTML in the original string. Whereas, if I place it at the end the action code first generates the new string and then adds on the existing content, thus not triggering the security measure.

Ah, thanks. But presumably this reverses the order of your assembled list? I’f so you could try assembling the new segment into a variable and add that now-string onto the end of the previous $TBXRelatedLessonHTML(source).

I’m not sure what this ‘security measure’ is. Is it documented as such anywhere? If not I think it perhaps should be.

I"m referring to your comment above " but when you have multiple related lessons then the order of that action code trips the security parameter."

1 Like

Ok, got it. Thanks.

1 Like