Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better slice json, do not use javascript constants after it #599

Closed
wants to merge 10 commits into from

Conversation

zba
Copy link
Contributor

@zba zba commented Apr 6, 2020

This will fix problems when youtube code recompiled and after json in config something unexpected.

fixes #585

@codecov
Copy link

codecov bot commented Apr 6, 2020

Codecov Report

Merging #599 into master will decrease coverage by 0.51%.
The diff coverage is 91.30%.

Impacted file tree graph

@@             Coverage Diff             @@
##            master     #599      +/-   ##
===========================================
- Coverage   100.00%   99.48%   -0.52%     
===========================================
  Files            7        7              
  Lines          558      580      +22     
===========================================
+ Hits           558      577      +19     
- Misses           0        3       +3     
Impacted Files Coverage Δ
lib/util.js 98.76% <90.90%> (-1.24%) ⬇️
lib/info.js 99.25% <100.00%> (-0.75%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9107e2d...2d3cec1. Read the comment docs.

@lgtm-com
Copy link

lgtm-com bot commented Apr 6, 2020

This pull request introduces 1 alert when merging edf71f2 into 9107e2d - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

Copy link
Collaborator

@TimeForANinja TimeForANinja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the pr 👍
got some minor thinks i wanna point at

lib/util.js Outdated Show resolved Hide resolved
lib/util.js Outdated Show resolved Hide resolved
Comment on lines 437 to 465
describe('util.cutAfterJSON()', () => {
it('works with simple JSON', () => {
assert.equal(util.cutAfterJSON('{"a": 1, "b": 1}'), '{"a": 1, "b": 1}');
});
it('Cut extra characters after JSON end', () => {
assert.equal(util.cutAfterJSON('{"a": 1, "b": 1}abcd'), '{"a": 1, "b": 1}');
});
it('tolerant to string constants', () => {
assert.equal(util.cutAfterJSON('{"a": "}1", "b": 1}abcd'), '{"a": "}1", "b": 1}');
});
it('tolerant to string with escaped quoting', () => {
assert.equal(util.cutAfterJSON('{"a": "\\\"}1", "b": 1}abcd'), '{"a": "\\\"}1", "b": 1}');
});
it('works with nested', () => {
assert.equal(util.cutAfterJSON(
'{"a": "\\\"1", "b": 1, "c": {"test": 1}}abcd'),
'{"a": "\\\"1", "b": 1, "c": {"test": 1}}');
});
it('works with utf', () => {
assert.equal(util.cutAfterJSON(
'{"a": "\\\"фыва", "b": 1, "c": {"test": 1}}abcd'),
'{"a": "\\\"фыва", "b": 1, "c": {"test": 1}}');
});
it('works with \\\\ in string', () => {
assert.equal(util.cutAfterJSON(
'{"a": "\\\\фыва", "b": 1, "c": {"test": 1}}abcd'),
'{"a": "\\\\фыва", "b": 1, "c": {"test": 1}}');
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some newlines to match the rest would be appreciated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean make arguments on new lines like last 3 tests done ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know whe're not 100% consistent but sth like a \n before the describe and some more between those it

lib/util.js Outdated Show resolved Hide resolved
@fent
Copy link
Owner

fent commented Apr 6, 2020

this is clever, I like 👍

@TimeForANinja thanks for taking a look

@zba
Copy link
Contributor Author

zba commented Apr 7, 2020

I also think it would be better to make a function to extract jsons from js/html files and search ones which having expected content, it would fix many random errors in parts, where json extracted.

@lgtm-com
Copy link

lgtm-com bot commented Apr 7, 2020

This pull request introduces 1 alert when merging 239a371 into 9107e2d - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

Aleksei Zbiniakov and others added 3 commits April 7, 2020 17:44
Copy link
Owner

@fent fent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since merging in the eslint PR, there are now new conflicts. do you mind looking at them?

there's also missing coverage in cutAfterJson()

image

this one is simple, it needs a json string that's wrapped in an array, not object.

* @param {String} mixedJson
* @return {String}
*/
exports.cutAfterJSON = function(mixedJson) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use arrow functions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should always return, but the return statement is conditioned?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, good catch. if the counter is over 0, then it's unclosed json, invalid, and should throw.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright am I being an idiot or does this function not actually cut the JSON at all, but is currently just verifying its integrity.....lastIndexOf(';ytplayer.load') is dropped, so this function is handling the uncut JSON...

I personally think it should cut it as soon as it faces a semi-colon with isString at false

return mixedJson.substr(0, i+1);
}
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing semicolon


/**
* Match begin and end braces of input JSON, return only json
* it works with braced jsons only!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON is always braced.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quoted string and unquoted number, and boolean are valid JSON
JSON.parse('1') // 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error parsing config: Unexpected token ; in JSON at position
4 participants