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
e57c3fe2
Commit
e57c3fe2
authored
Jul 22, 2021
by
Matthias Käppler
Committed by
Heinrich Lee Yu
Jul 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Flag ActiveSupport::JSON in Gitlab::Json Cop
parent
2eba76ca
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
36 additions
and
25 deletions
+36
-25
.rubocop.yml
.rubocop.yml
+0
-1
db/post_migrate/20190517153211_migrate_k8s_service_integration.rb
...migrate/20190517153211_migrate_k8s_service_integration.rb
+1
-1
ee/spec/lib/gitlab/geo/oauth/session_spec.rb
ee/spec/lib/gitlab/geo/oauth/session_spec.rb
+2
-2
lib/gitlab/import_export/json/legacy_reader.rb
lib/gitlab/import_export/json/legacy_reader.rb
+1
-1
lib/gitlab/import_export/json/ndjson_reader.rb
lib/gitlab/import_export/json/ndjson_reader.rb
+2
-2
lib/gitlab/import_export/lfs_restorer.rb
lib/gitlab/import_export/lfs_restorer.rb
+1
-1
lib/gitlab/json_cache.rb
lib/gitlab/json_cache.rb
+2
-2
rubocop/cop/gitlab/json.rb
rubocop/cop/gitlab/json.rb
+1
-1
spec/features/projects/import_export/export_file_spec.rb
spec/features/projects/import_export/export_file_spec.rb
+1
-2
spec/lib/gitlab/import_export/group/legacy_tree_restorer_spec.rb
...b/gitlab/import_export/group/legacy_tree_restorer_spec.rb
+1
-1
spec/lib/gitlab/import_export/group/tree_restorer_spec.rb
spec/lib/gitlab/import_export/group/tree_restorer_spec.rb
+1
-1
spec/lib/gitlab/import_export/import_test_coverage_spec.rb
spec/lib/gitlab/import_export/import_test_coverage_spec.rb
+1
-1
spec/lib/gitlab/json_cache_spec.rb
spec/lib/gitlab/json_cache_spec.rb
+3
-3
spec/requests/git_http_spec.rb
spec/requests/git_http_spec.rb
+2
-2
spec/rubocop/cop/gitlab/json_spec.rb
spec/rubocop/cop/gitlab/json_spec.rb
+14
-1
spec/support/import_export/common_util.rb
spec/support/import_export/common_util.rb
+3
-3
No files found.
.rubocop.yml
View file @
e57c3fe2
...
...
@@ -254,7 +254,6 @@ Gitlab/HTTParty:
Gitlab/Json
:
Enabled
:
true
Exclude
:
-
'
db/**/*'
-
'
qa/**/*'
-
'
scripts/**/*'
-
'
tooling/rspec_flaky/**/*'
...
...
db/post_migrate/20190517153211_migrate_k8s_service_integration.rb
View file @
e57c3fe2
...
...
@@ -70,7 +70,7 @@ class MigrateK8sServiceIntegration < ActiveRecord::Migration[5.1]
private
def
parsed_properties
@parsed_properties
||=
JSON
.
parse
(
self
.
properties
)
@parsed_properties
||=
JSON
.
parse
(
self
.
properties
)
# rubocop:disable Gitlab/Json
end
end
...
...
ee/spec/lib/gitlab/geo/oauth/session_spec.rb
View file @
e57c3fe2
...
...
@@ -49,7 +49,7 @@ RSpec.describe Gitlab::Geo::Oauth::Session, :geo do
describe
'#authenticate'
do
let
(
:api_url
)
{
"
#{
primary_node
.
internal_url
.
chomp
(
'/'
)
}
/api/v4/user"
}
let
(
:user_json
)
{
ActiveSupport
::
JSON
.
encode
({
id:
555
,
email:
'user@example.com'
}.
as_json
)
}
let
(
:user_json
)
{
Gitlab
::
Json
.
dump
({
id:
555
,
email:
'user@example.com'
}.
as_json
)
}
context
'on success'
do
before
do
...
...
@@ -96,7 +96,7 @@ RSpec.describe Gitlab::Geo::Oauth::Session, :geo do
describe
'#get_token'
do
context
'primary is configured with relative URL'
do
it
"makes the request to a primary's relative URL"
do
response
=
ActiveSupport
::
JSON
.
encode
({
access_token:
'fake-token'
}.
as_json
)
response
=
Gitlab
::
Json
.
dump
({
access_token:
'fake-token'
}.
as_json
)
primary_node
.
update!
(
url:
'http://example.com/gitlab/'
)
api_url
=
"
#{
primary_node
.
internal_url
}
oauth/token"
...
...
lib/gitlab/import_export/json/legacy_reader.rb
View file @
e57c3fe2
...
...
@@ -27,7 +27,7 @@ module Gitlab
end
def
read_hash
ActiveSupport
::
JSON
.
decod
e
(
IO
.
read
(
@path
))
Gitlab
::
Json
.
pars
e
(
IO
.
read
(
@path
))
rescue
StandardError
=>
e
Gitlab
::
ErrorTracking
.
log_exception
(
e
)
raise
Gitlab
::
ImportExport
::
Error
,
'Incorrect JSON format'
...
...
lib/gitlab/import_export/json/ndjson_reader.rb
View file @
e57c3fe2
...
...
@@ -47,8 +47,8 @@ module Gitlab
private
def
json_decode
(
string
)
ActiveSupport
::
JSON
.
decod
e
(
string
)
rescue
ActiveSupport
::
JSON
.
parse_e
rror
=>
e
Gitlab
::
Json
.
pars
e
(
string
)
rescue
JSON
::
ParserE
rror
=>
e
Gitlab
::
ErrorTracking
.
log_exception
(
e
)
raise
Gitlab
::
ImportExport
::
Error
,
'Incorrect JSON format'
end
...
...
lib/gitlab/import_export/lfs_restorer.rb
View file @
e57c3fe2
...
...
@@ -72,7 +72,7 @@ module Gitlab
@lfs_json
||=
begin
json
=
IO
.
read
(
lfs_json_path
)
ActiveSupport
::
JSON
.
decod
e
(
json
)
Gitlab
::
Json
.
pars
e
(
json
)
rescue
StandardError
raise
Gitlab
::
ImportExport
::
Error
,
'Incorrect JSON format'
end
...
...
lib/gitlab/json_cache.rb
View file @
e57c3fe2
...
...
@@ -58,7 +58,7 @@ module Gitlab
private
def
parse_value
(
raw
,
klass
)
value
=
ActiveSupport
::
JSON
.
decod
e
(
raw
.
to_s
)
value
=
Gitlab
::
Json
.
pars
e
(
raw
.
to_s
)
case
value
when
Hash
then
parse_entry
(
value
,
klass
)
...
...
@@ -66,7 +66,7 @@ module Gitlab
else
value
end
rescue
ActiveSupport
::
JSON
.
parse_e
rror
rescue
JSON
::
ParserE
rror
nil
end
...
...
rubocop/cop/gitlab/json.rb
View file @
e57c3fe2
...
...
@@ -10,7 +10,7 @@ module RuboCop
EOL
def_node_matcher
:json_node?
,
<<~
PATTERN
(send (const
nil?
:JSON)...)
(send (const
{nil? | (const nil? :ActiveSupport)}
:JSON)...)
PATTERN
def
on_send
(
node
)
...
...
spec/features/projects/import_export/export_file_spec.rb
View file @
e57c3fe2
...
...
@@ -82,8 +82,7 @@ RSpec.describe 'Import/Export - project export integration test', :js do
relations
<<
Gitlab
::
Json
.
parse
(
IO
.
read
(
project_json_path
))
Dir
.
glob
(
File
.
join
(
tmpdir
,
'tree/project'
,
'*.ndjson'
))
do
|
rb_filename
|
File
.
foreach
(
rb_filename
)
do
|
line
|
json
=
ActiveSupport
::
JSON
.
decode
(
line
)
relations
<<
json
relations
<<
Gitlab
::
Json
.
parse
(
line
)
end
end
...
...
spec/lib/gitlab/import_export/group/legacy_tree_restorer_spec.rb
View file @
e57c3fe2
...
...
@@ -77,7 +77,7 @@ RSpec.describe Gitlab::ImportExport::Group::LegacyTreeRestorer do
let
(
:group
)
{
create
(
:group
)
}
let
(
:shared
)
{
Gitlab
::
ImportExport
::
Shared
.
new
(
group
)
}
let
(
:group_tree_restorer
)
{
described_class
.
new
(
user:
importer_user
,
shared:
shared
,
group:
group
,
group_hash:
nil
)
}
let
(
:group_json
)
{
ActiveSupport
::
JSON
.
decod
e
(
IO
.
read
(
File
.
join
(
shared
.
export_path
,
'group.json'
)))
}
let
(
:group_json
)
{
Gitlab
::
Json
.
pars
e
(
IO
.
read
(
File
.
join
(
shared
.
export_path
,
'group.json'
)))
}
shared_examples
'excluded attributes'
do
excluded_attributes
=
%w[
...
...
spec/lib/gitlab/import_export/group/tree_restorer_spec.rb
View file @
e57c3fe2
...
...
@@ -111,7 +111,7 @@ RSpec.describe Gitlab::ImportExport::Group::TreeRestorer do
let
(
:shared
)
{
Gitlab
::
ImportExport
::
Shared
.
new
(
group
)
}
let
(
:group_tree_restorer
)
{
described_class
.
new
(
user:
importer_user
,
shared:
shared
,
group:
group
)
}
let
(
:exported_file
)
{
File
.
join
(
shared
.
export_path
,
'tree/groups/4352.json'
)
}
let
(
:group_json
)
{
ActiveSupport
::
JSON
.
decod
e
(
IO
.
read
(
exported_file
))
}
let
(
:group_json
)
{
Gitlab
::
Json
.
pars
e
(
IO
.
read
(
exported_file
))
}
shared_examples
'excluded attributes'
do
excluded_attributes
=
%w[
...
...
spec/lib/gitlab/import_export/import_test_coverage_spec.rb
View file @
e57c3fe2
...
...
@@ -86,7 +86,7 @@ RSpec.describe 'Test coverage of the Project Import' do
end
def
relations_from_json
(
json_file
)
json
=
ActiveSupport
::
JSON
.
decod
e
(
IO
.
read
(
json_file
))
json
=
Gitlab
::
Json
.
pars
e
(
IO
.
read
(
json_file
))
[].
tap
{
|
res
|
gather_relations
({
project:
json
},
res
,
[])}
.
map
{
|
relation_names
|
relation_names
.
join
(
'.'
)}
...
...
spec/lib/gitlab/json_cache_spec.rb
View file @
e57c3fe2
...
...
@@ -130,7 +130,7 @@ RSpec.describe Gitlab::JsonCache do
.
with
(
expanded_key
)
.
and_return
(
nil
)
expect
(
ActiveSupport
::
JSON
).
not_to
receive
(
:decod
e
)
expect
(
Gitlab
::
Json
).
not_to
receive
(
:pars
e
)
expect
(
cache
.
read
(
key
)).
to
be_nil
end
...
...
@@ -140,7 +140,7 @@ RSpec.describe Gitlab::JsonCache do
.
with
(
expanded_key
)
.
and_return
(
true
)
expect
(
ActiveSupport
::
JSON
).
to
receive
(
:decod
e
).
with
(
"true"
).
and_call_original
expect
(
Gitlab
::
Json
).
to
receive
(
:pars
e
).
with
(
"true"
).
and_call_original
expect
(
cache
.
read
(
key
,
BroadcastMessage
)).
to
eq
(
true
)
end
end
...
...
@@ -151,7 +151,7 @@ RSpec.describe Gitlab::JsonCache do
.
with
(
expanded_key
)
.
and_return
(
false
)
expect
(
ActiveSupport
::
JSON
).
to
receive
(
:decod
e
).
with
(
"false"
).
and_call_original
expect
(
Gitlab
::
Json
).
to
receive
(
:pars
e
).
with
(
"false"
).
and_call_original
expect
(
cache
.
read
(
key
,
BroadcastMessage
)).
to
eq
(
false
)
end
end
...
...
spec/requests/git_http_spec.rb
View file @
e57c3fe2
...
...
@@ -267,7 +267,7 @@ RSpec.describe 'Git HTTP requests' do
it
"responds to pulls with the wiki's repo"
do
download
(
path
)
do
|
response
|
json_body
=
ActiveSupport
::
JSON
.
decod
e
(
response
.
body
)
json_body
=
Gitlab
::
Json
.
pars
e
(
response
.
body
)
expect
(
json_body
[
'Repository'
][
'relative_path'
]).
to
eq
(
wiki
.
repository
.
relative_path
)
end
...
...
@@ -1584,7 +1584,7 @@ RSpec.describe 'Git HTTP requests' do
it
"responds to pulls with the wiki's repo"
do
download
(
path
)
do
|
response
|
json_body
=
ActiveSupport
::
JSON
.
decod
e
(
response
.
body
)
json_body
=
Gitlab
::
Json
.
pars
e
(
response
.
body
)
expect
(
json_body
[
'Repository'
][
'relative_path'
]).
to
eq
(
wiki
.
repository
.
relative_path
)
end
...
...
spec/rubocop/cop/gitlab/json_spec.rb
View file @
e57c3fe2
...
...
@@ -6,7 +6,7 @@ require_relative '../../../../rubocop/cop/gitlab/json'
RSpec
.
describe
RuboCop
::
Cop
::
Gitlab
::
Json
do
subject
(
:cop
)
{
described_class
.
new
}
context
'when JSON is called'
do
context
'when
::
JSON is called'
do
it
'registers an offense'
do
expect_offense
(
<<~
RUBY
)
class Foo
...
...
@@ -18,4 +18,17 @@ RSpec.describe RuboCop::Cop::Gitlab::Json do
RUBY
end
end
context
'when ActiveSupport::JSON is called'
do
it
'registers an offense'
do
expect_offense
(
<<~
RUBY
)
class Foo
def bar
ActiveSupport::JSON.parse('{ "foo": "bar" }')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid calling `JSON` directly. [...]
end
end
RUBY
end
end
end
spec/support/import_export/common_util.rb
View file @
e57c3fe2
...
...
@@ -83,7 +83,7 @@ module ImportExport
path
=
File
.
join
(
dir_path
,
"
#{
exportable_path
}
.json"
)
return
unless
File
.
exist?
(
path
)
ActiveSupport
::
JSON
.
decod
e
(
IO
.
read
(
path
))
Gitlab
::
Json
.
pars
e
(
IO
.
read
(
path
))
end
def
consume_relations
(
dir_path
,
exportable_path
,
key
)
...
...
@@ -93,7 +93,7 @@ module ImportExport
relations
=
[]
File
.
foreach
(
path
)
do
|
line
|
json
=
ActiveSupport
::
JSON
.
decod
e
(
line
)
json
=
Gitlab
::
Json
.
pars
e
(
line
)
relations
<<
json
end
...
...
@@ -101,7 +101,7 @@ module ImportExport
end
def
project_json
(
filename
)
ActiveSupport
::
JSON
.
decod
e
(
IO
.
read
(
filename
))
Gitlab
::
Json
.
pars
e
(
IO
.
read
(
filename
))
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