Skip to content

320159: main part (work in progress) #140

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions lib/refix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
'use strict';

/*
* Note: this fixes only some known bad patterns which appear in the upsteam
* uap-core lib.
*
* It doesn't make a generic regexp safe!
*
* All new regexps should be taken through Weideman's tool and analyzed
* individually.
*
*/

// Order is important!
var replaces = [
/*
* Trimming looks like a good change
* FIXME: this block doesn't pass uap-core tests yet
*/
[' *([^;]*) *', ' *([^; ][^;]*[^; ]|[^; ]?) *'],
[' *([^;]+) *', ' *([^; ][^;]*[^; ]|[^; ]) *'],
[' *([^;]+) *', ' *([^; ][^;]*[^; ]|[^; ]) *'], // Twice!
['([^;/]+) *', '([^;/]*[^;/ ]) *'],
['([^;/]*) *', '([^;/]*[^;/ ]|) *'],
['([^/;\\)]+) *', '([^/;\\) ]*[^/;\\) ]) *'],

/*
* Pure representation changes with lookahead magic
*/
['[^\\);]+)[^\\);]*', '[^\\);]+(?=[\\);]))[^\\);]*'],

/*
* Pure representation changes (should not affect the result)
*/
//['(\\d+)\\.?(\\d+)?.?(\\d+)?.?(\\d+)?', '(\\d+)(?:\\.(\\d+)?(?:[^\\d](\\d+)?(?:[^\\d](\\d+)?)?)?)?'], // NOT FOUND ANYMORE
//['(\\d+)\\.?(\\d+)?\\.?(\\d+)?\\.?(\\d+)?', '(\\d+)(?:\\.(\\d+)?(?:\\.(\\d+)?(?:\\.(\\d+)?)?)?)?'], // NOT FOUND ANYMORE
//['(\\d+)\\.(\\d+)\\.?(\\d+)?\\.?(\\d+)?', '(\\d+)\\.(\\d+)(?:\\.(\\d+)?(?:\\.(\\d+)?)?)?'], // NOT FOUND ANYMORE
//['(\\d+)\\.(\\d+)\\.?(\\d+)?', '(\\d+)\\.(\\d+)(?:\\.(\\d+)?)?'], // NOT FOUND ANYMORE
//['(\\d+)\\.?(\\d+)?', '(\\d+)(?:\\.(\\d+)?)?'], // NOT FOUND ANYMORE
//['([^.\\s]+)\\.([^.\\s]+)?\\.?([^.\\s]+)?', '([^.\\s]+)\\.([^.\\s]+)?(?:\\.([^.\\s]+)?)?'], // NOT FOUND ANYMORE
['(\\d+).+', '(\\d+)[^\\d].*'],
['(\\d+)[\\d.]*', '(\\d+)(?:\\.[\\d.]*)?'],
['(\\d+).*', '(\\d+)(?:[^\\d].+)?'],
['\\d+[A-z0-9_]*', '\\d+(?:[A-z_][A-z0-9_]*)?'],
['\\d+[^;/]+', '\\d+(?:[^;/\\d][^;/]*|[^;/])'],
['\\d+[^;/]*', '\\d+(?:[^;/\\d][^;/]*)?'],
['\\d+[^ ;/]*', '\\d+(?:[^ ;/\\d][^ ;/]*)?'],
['\\d+[^;]*', '\\d+(?:[^;\\d][^;]*)?'],
['\\d+[^\\);]+', '\\d+(?:[^\\);\\d][^\\);]*|[^\\);])'],
[' *([^;,\\)]+)', ' *([^;,\\) ][^;,\\)]*|[^;,\\)])'],
[' *([^;\\/]+)', ' *([^;\\/ ][^;\\/]+|[^;\\/])'],
[' *([^;/]+)', ' *([^;/ ][^;/]+|[^;/])'],
[' *([^;]+)', ' *([^; ][^;]+|[^;])'],
[' *[^;/]+', ' *(?:[^;/ ][^;/]+|[^;/])'],
[' *([^;/]*)', ' *([^;/ ][^;/]+|[^;/]?)'],
['([A-Za-z0-9\\-]+).*', '([A-Za-z0-9\\-]+)(?:[^A-Za-z0-9\\-].*)?'],
[' *(.*?)', ' *([^ ].*?|)'],
['\\.\\d+.*', '\\.\\d+(?:[^\\d].*|)?'],
['(?:HTC|Htc|HTC_blocked[^;]*)[^;]*', '(?:HTC|Htc|HTC_blocked)[^;]*'],
['(?:CUS:([^;]*)|([^;]+)) *', '(?:CUS:([^;]*[^; ]|)|([^;]+[^; ]|[^;])) *'],
//['(?:.*SW-Version/.*)*', '(?:.*SW-Version/.*)?'], // NOT FOUND ANYMORE
//['(\\d+)\\.?([^.\\s]+)?\\.?([^.\\s]+)?', '(\\d+)\\.?([^.\\s]+)?(?:\\.([^.\\s]+)?)?'], // NOT FOUND ANYMORE
//[')? *([A-Za-z0-9 \\-_\\!\\[\\]:]*', ')? *((?:[A-Za-z0-9\\-_\\!\\[\\]:][A-Za-z0-9 \\-_\\!\\[\\]:]*)?'], // NOT FOUND ANYMORE
//[')? *([A-Za-z0-9 _\\!\\[\\]:]*', ')? *((?:[A-Za-z0-9_\\!\\[\\]:][A-Za-z0-9 _\\!\\[\\]:]*)?'], // NOT FOUND ANYMORE
/*
* Don't change the result of the specific regexps
* (possibly due to presense of other regexps with similar result)
*/
['(\\d+).(\\d+)\\.(\\d+)', '(\\d+)[^\\d](\\d+)\\.(\\d+)'],

/*
* Length limit, should be fine for all known testcases
*/
['CPU.*OS[ +](\\d+)', 'CPU.{0,40}OS[ +](\\d+)'],

/*
* Non-greedy sometimes helps
*/
['Mobile.*[ +]Safari', 'Mobile.*?[ +]Safari'],
[';.*(201[1-9]).*', ';.*?(201[1-9]).*?'],

/*
* Changing . to \. will break 1-0-0 support, changing to [^\d] will break foo/10000 support
* We don't want to parse foo/10000 as 1.0.0, let's parse it as 10000.0.0
*/
//['(\\d+).(\\d+).(\\d+).(\\d+)', '(\\d+)(?:[^\\d](\\d+)(?:[^\\d](\\d+)(?:[^\\d](\\d+))?)?)?'], // NOT FOUND ANYMORE
['(\\d+).(\\d+).(\\d+)', '(\\d+)(?:[^\\d](\\d+)(?:[^\\d](\\d+))?)?'],
['(\\d+).(\\d+)', '(\\d+)(?:[^\\d](\\d+))?']
];

function fix(pattern) {
for (var i in replaces) {
var row = replaces[i];
if (pattern.indexOf(row[0]) === -1) continue;
pattern = pattern.replace(row[0], row[1]);
}
return pattern;
}

module.exports = { fix: fix };
Loading