Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
ce316c1d
Commit
ce316c1d
authored
9 years ago
by
Tom Robinson
Browse files
Options
Downloads
Patches
Plain Diff
Base64 unit tests
parent
d0cb75ac
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
frontend/src/card/card.controllers.js
+1
-1
1 addition, 1 deletion
frontend/src/card/card.controllers.js
frontend/src/lib/card.js
+4
-4
4 additions, 4 deletions
frontend/src/lib/card.js
frontend/test/unit/lib/card.spec.js
+35
-0
35 additions, 0 deletions
frontend/test/unit/lib/card.spec.js
with
40 additions
and
5 deletions
frontend/src/card/card.controllers.js
+
1
−
1
View file @
ce316c1d
...
...
@@ -18,7 +18,7 @@ import DataGrid from "metabase/lib/data_grid";
import
{
addValidOperatorsToFields
}
from
"
metabase/lib/schema_metadata
"
;
import
Query
from
"
metabase/lib/query
"
;
import
{
serializeCardForUrl
,
deserializeCardFromUrl
,
cleanCopyCard
,
urlForCardState
}
from
'
./card.util
'
;
import
{
serializeCardForUrl
,
deserializeCardFromUrl
,
cleanCopyCard
,
urlForCardState
}
from
"
metabase/lib/card
"
;
import
*
as
reducers
from
'
./reducers
'
;
...
...
This diff is collapsed.
Click to expand it.
frontend/src/
card
/card.
util.
js
→
frontend/src/
lib
/card.js
+
4
−
4
View file @
ce316c1d
...
...
@@ -21,18 +21,18 @@ export function deserializeCardFromUrl(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
)
{
export
function
utf8_to_b64
(
str
)
{
return
window
.
btoa
(
unescape
(
encodeURIComponent
(
str
)));
}
function
b64_to_utf8
(
b64
)
{
export
function
b64_to_utf8
(
b64
)
{
return
decodeURIComponent
(
escape
(
window
.
atob
(
b64
)));
}
// for "URL safe" base64, replace "+" with "-" and "/" with "_" as per RFC 4648
function
utf8_to_b64url
(
str
)
{
export
function
utf8_to_b64url
(
str
)
{
return
utf8_to_b64
(
str
).
replace
(
/
\+
/g
,
"
-
"
).
replace
(
/
\/
/g
,
"
_
"
);
}
function
b64url_to_utf8
(
b64url
)
{
export
function
b64url_to_utf8
(
b64url
)
{
return
b64_to_utf8
(
b64url
.
replace
(
/-/g
,
"
+
"
).
replace
(
/_/g
,
"
/
"
))
}
...
...
This diff is collapsed.
Click to expand it.
frontend/test/unit/lib/card.spec.js
0 → 100644
+
35
−
0
View file @
ce316c1d
import
{
utf8_to_b64
,
b64_to_utf8
,
utf8_to_b64url
,
b64url_to_utf8
}
from
'
metabase/lib/card
'
;
describe
(
'
card
'
,
()
=>
{
describe
(
'
utf8_to_b64
'
,
()
=>
{
it
(
'
should encode with non-URL-safe characters
'
,
()
=>
{
expect
(
utf8_to_b64
(
"
?
"
).
indexOf
(
"
/
"
)).
toEqual
(
3
);
expect
(
utf8_to_b64
(
"
?
"
)).
toEqual
(
"
ICA/
"
);
});
});
describe
(
'
b64_to_utf8
'
,
()
=>
{
it
(
'
should decode corretly
'
,
()
=>
{
expect
(
b64_to_utf8
(
"
ICA/
"
)).
toEqual
(
"
?
"
);
});
});
describe
(
'
utf8_to_b64url
'
,
()
=>
{
it
(
'
should encode with URL-safe characters
'
,
()
=>
{
expect
(
utf8_to_b64url
(
"
?
"
).
indexOf
(
"
/
"
)).
toEqual
(
-
1
);
expect
(
utf8_to_b64url
(
"
?
"
)).
toEqual
(
"
ICA_
"
);
});
});
describe
(
'
b64url_to_utf8
'
,
()
=>
{
it
(
'
should decode corretly
'
,
()
=>
{
expect
(
b64url_to_utf8
(
"
ICA_
"
)).
toEqual
(
"
?
"
);
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment