Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b02a0313
Commit
b02a0313
authored
May 04, 2020
by
Robert May
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some improvements to json wrapper
parent
edca1543
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
lib/gitlab/json.rb
lib/gitlab/json.rb
+8
-5
spec/lib/gitlab/json_spec.rb
spec/lib/gitlab/json_spec.rb
+3
-3
No files found.
lib/gitlab/json.rb
View file @
b02a0313
...
...
@@ -2,12 +2,14 @@
module
Gitlab
module
Json
INVALID_LEGACY_TYPES
=
[
String
,
TrueClass
,
FalseClass
].
freeze
class
<<
self
def
parse
(
string
,
*
args
,
**
named_args
)
legacy_mode
=
legacy_mode_enabled?
(
named_args
.
delete
(
:legacy_mode
))
data
=
adapter
.
parse
(
string
,
*
args
,
**
named_args
)
raise
parser_error
if
legacy_mode
&&
[
String
,
TrueClass
,
FalseClass
]
.
any?
{
|
type
|
data
.
is_a?
(
type
)
}
raise
parser_error
if
legacy_mode
&&
INVALID_LEGACY_TYPES
.
any?
{
|
type
|
data
.
is_a?
(
type
)
}
data
end
...
...
@@ -39,10 +41,11 @@ module Gitlab
end
def
legacy_mode_enabled?
(
arg_value
)
# This will change to the following once the `json` gem is upgraded:
# arg_value.nil? ? true : arg_value
true
if
::
JSON
::
VERSION_MAJOR
>=
2
arg_value
.
nil?
?
true
:
arg_value
else
true
end
end
end
end
...
...
spec/lib/gitlab/json_spec.rb
View file @
b02a0313
...
...
@@ -40,15 +40,15 @@ RSpec.describe Gitlab::Json do
# will be updated accordingly.
it
"raises an error on a string"
do
expect
{
subject
.
parse
(
'"foo"'
)
}.
to
raise_error
(
JSON
::
ParserError
)
expect
{
subject
.
parse
(
'"foo"'
,
legacy_mode:
false
)
}.
to
raise_error
(
JSON
::
ParserError
)
end
it
"raises an error on a true bool"
do
expect
{
subject
.
parse
(
"true"
)
}.
to
raise_error
(
JSON
::
ParserError
)
expect
{
subject
.
parse
(
"true"
,
legacy_mode:
false
)
}.
to
raise_error
(
JSON
::
ParserError
)
end
it
"raises an error on a false bool"
do
expect
{
subject
.
parse
(
"false"
)
}.
to
raise_error
(
JSON
::
ParserError
)
expect
{
subject
.
parse
(
"false"
,
legacy_mode:
false
)
}.
to
raise_error
(
JSON
::
ParserError
)
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment