diff --git a/source/nodejs/adaptivecards-site/themes/adaptivecards/layout/designer.ejs b/source/nodejs/adaptivecards-site/themes/adaptivecards/layout/designer.ejs index 7aa684a421..cff33b82d1 100644 --- a/source/nodejs/adaptivecards-site/themes/adaptivecards/layout/designer.ejs +++ b/source/nodejs/adaptivecards-site/themes/adaptivecards/layout/designer.ejs @@ -144,27 +144,34 @@ designer.attachTo(document.getElementById("designerRootHost")); designer.monacoModuleLoaded(); - var cardUrl = getParameterByName("card", null); - var dataUrl = getParameterByName("data", null); - - if (dataUrl) { - var dataXhttp = new XMLHttpRequest(); - dataXhttp.onload = function () { - if (dataXhttp.responseText && dataXhttp.responseText != "") { - var sampleData = JSON.parse(dataXhttp.responseText); - designer.sampleData = sampleData; - } - }; - - // TODO: when the designer has an addError API we should log that we failed to load the requested card - // xhttp.onerror = function() { - // designer. - // }; + var cardParam = getParameterByName("card", null); + var dataParam = getParameterByName("data", null); + if (dataParam) { try { - dataXhttp.open("GET", dataUrl, true); + var dataUrl = new URL(dataParam); + var dataXhttp = new XMLHttpRequest(); + dataXhttp.onload = function () { + if (dataXhttp.responseText && dataXhttp.responseText != "") { + var sampleData = JSON.parse(dataXhttp.responseText); + designer.sampleData = sampleData; + } + }; + + // TODO: when the designer has an addError API we should log that we failed to load the requested card + // xhttp.onerror = function() { + // designer. + // }; + + dataXhttp.open("GET", dataParam, true); dataXhttp.send(); } catch (e) { + // Check if the data is a valid JSON + try { + var sampleData = JSON.parse(dataParam); + designer.sampleData = sampleData; + } catch (e) { + } } } else { // Add sample data @@ -188,25 +195,31 @@ designer.sampleData = sampleData; } - if (cardUrl) { - var cardXhttp = new XMLHttpRequest(); - cardXhttp.onload = function () { - if (cardXhttp.responseText && cardXhttp.responseText != "") { - designer.setCard(JSON.parse(cardXhttp.responseText)); - } - - history.replaceState(null, null, "<%- config.root %>designer"); - }; - - // TODO: when the designer has an addError API we should log that we failed to load the requested card - // xhttp.onerror = function() { - // designer. - // }; - - try { - cardXhttp.open("GET", cardUrl, true); + if (cardParam) { + try{ + var cardUrl = new URL(cardParam); + var cardXhttp = new XMLHttpRequest(); + cardXhttp.onload = function () { + if (cardXhttp.responseText && cardXhttp.responseText != "") { + designer.setCard(JSON.parse(cardXhttp.responseText)); + } + + history.replaceState(null, null, "<%- config.root %>designer"); + }; + + // TODO: when the designer has an addError API we should log that we failed to load the requested card + // xhttp.onerror = function() { + // designer. + // }; + + cardXhttp.open("GET", cardParam, true); cardXhttp.send(); } catch (e) { + // Check if the card is a valid JSON + try { + designer.setCard(JSON.parse(cardParam)); + } catch (e) { + } } } else { designer.setCard({