Skip to content

Commit 9738e85

Browse files
committed
docs: Guard tutorial urls
When using a tutorial where we update the url to include the source, the url can end in characters that some services misinterpret (e.g., if the url ends in `.`, slack assumes that the `.` is not part of the url). If the last `src` chunk added does not end in an alphanumeric value, add a `_=_` property to guard the end of the url.
1 parent a43155f commit 9738e85

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tutorials/common/tutorials.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ function start_keeper(alwaysKeep) {
280280
if (query.keep && alwaysKeep !== true) {
281281
newQuery.keep = query.keep;
282282
}
283+
var guard = false;
283284
$('.codeblock').each(function () {
284285
var block = $(this),
285286
defaultSrc = $('textarea', block).attr('defaultvalue'),
@@ -295,8 +296,12 @@ function start_keeper(alwaysKeep) {
295296
* average length of the url by 6 percent. */
296297
comp = comp.replace(/\//g, '.').replace(/\+/g, '-').replace(/=/g, '_');
297298
newQuery[key] = comp;
299+
guard = !(/[A-Za-z0-9]/.test(comp.slice(-1)));
298300
}
299301
});
302+
if (guard) {
303+
newQuery['_'] = '_';
304+
}
300305
if (!inPop) {
301306
utils.setQuery(newQuery, true);
302307
}

0 commit comments

Comments
 (0)