<commit_before>import Query from "metabase/lib/query";

export function serializeCardForUrl(card) {
    var dataset_query = angular.copy(card.dataset_query);
    if (dataset_query.query) {
        dataset_query.query = Query.cleanQuery(dataset_query.query);
    }
    var cardCopy = {
        name: card.name,
        description: card.description,
        dataset_query: dataset_query,
        display: card.display,
        visualization_settings: card.visualization_settings
    };
    return btoa(JSON.stringify(cardCopy));
}

export function deserializeCardFromUrl(serialized) {
    return JSON.parse(atob(serialized));
}

export function urlForCardState(state, dirty) {
    var url;<commit_msg>Don't blow up when saving a question with a unicode characters 😁<commit_after>import Query from "metabase/lib/query";

export function serializeCardForUrl(card) {
    var dataset_query = angular.copy(card.dataset_query);
    if (dataset_query.query) {
        dataset_query.query = Query.cleanQuery(dataset_query.query);
    }
    var cardCopy = {
        name: card.name,
        description: card.description,
        dataset_query: dataset_query,
        display: card.display,
        visualization_settings: card.visualization_settings
    };
    return utf8_to_b64(JSON.stringify(cardCopy));
}

export function deserializeCardFromUrl(serialized) {
    return JSON.parse(b64_to_utf8(serialized));
}

// escaping before base64 encoding is necessary for non-ASCII characters
// https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/btoa
function utf8_to_b64(str) {
    return window.btoa(unescape(encodeURIComponent(str)));
}
function b64_to_utf8(str) {
    return decodeURIComponent(escape(window.atob(str)));
}

export function urlForCardState(state, dirty) {
    var url;
{'fraction_non_alphanumeric': 0.10028011204481793, 'fraction_numerical': 0.008963585434173669, 'mean_word_length': 4.002801120448179, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1981990', 'n_tokens_mistral': 549, 'n_tokens_neox': 539, 'n_words': 106}