Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
diffoscope
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reproducible Builds
diffoscope
Commits
f581b2dd
Commit
f581b2dd
authored
6 years ago
by
Chris Lamb
Browse files
Options
Downloads
Patches
Plain Diff
comparators.json: Use File.file_header to tidy JSON matching.
parent
f0bf14f2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
diffoscope/comparators/json.py
+5
-7
5 additions, 7 deletions
diffoscope/comparators/json.py
with
5 additions
and
7 deletions
diffoscope/comparators/json.py
+
5
−
7
View file @
f581b2dd
...
...
@@ -35,14 +35,12 @@ class JSONFile(File):
@classmethod
def
recognizes
(
cls
,
file
):
with
open
(
file
.
path
,
'
rb
'
)
as
f
:
# Try fuzzy matching for JSON files
if
not
file
.
name
.
endswith
(
'
.json
'
):
buf
=
f
.
read
(
10
)
if
not
any
(
x
in
buf
for
x
in
b
'
{[
'
):
return
False
f
.
seek
(
0
)
# Try fuzzy matching for files not called .json
if
not
file
.
name
.
endswith
(
'
.json
'
):
if
b
'
{
'
not
in
file
.
file_header
or
b
'
[
'
not
in
file
.
file_header
:
return
False
with
open
(
file
.
path
,
'
rb
'
)
as
f
:
try
:
file
.
parsed
=
json
.
loads
(
f
.
read
().
decode
(
'
utf-8
'
,
errors
=
'
ignore
'
),
...
...
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