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

fix: python prevent infinite loop #75

Merged
merged 2 commits into from
Nov 2, 2023
Merged
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
22 changes: 17 additions & 5 deletions src/providers/python_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ export default class Python_controller {

}
}
bringAllDependencies(dependencies,getDependencyName(dep),CachedEnvironmentDeps,includeTransitive)
let path = new Array()
let depName = getDependencyName(dep)
//array to track a path for each branch in the dependency tree
path.push(depName.toLowerCase())
bringAllDependencies(dependencies,depName,CachedEnvironmentDeps,includeTransitive,path)
})
dependencies.sort((dep1,dep2) =>{
const DEP1 = dep1.name.toLowerCase()
Expand Down Expand Up @@ -247,7 +251,7 @@ function getDependencyVersion(record) {
* @return {string} the name of dependency
*/
function getDependencyName(depLine) {
const regex = /[^\w\s-_]/g;
const regex = /[^\w\s-_.]/g;
let endIndex = depLine.search(regex);
return depLine.substring(0,endIndex) ;
}
Expand All @@ -272,8 +276,9 @@ function getDepsList(record) {
* @param dependencyName
* @param cachedEnvironmentDeps
* @param includeTransitive
* @param {[string]}path array representing the path of the current branch in dependency tree, starting with a root dependency - that is - a given dependency in requirements.txt
*/
function bringAllDependencies(dependencies, dependencyName, cachedEnvironmentDeps, includeTransitive) {
function bringAllDependencies(dependencies, dependencyName, cachedEnvironmentDeps, includeTransitive,path) {
if(dependencyName === null || dependencyName === undefined || dependencyName.trim() === "" ) {
return
}
Expand All @@ -292,8 +297,15 @@ function bringAllDependencies(dependencies, dependencyName, cachedEnvironmentDep
let entry = { "name" : getDependencyNameShow(record) , "version" : version, "dependencies" : [] }
dependencies.push(entry)
directDeps.forEach( (dep) => {
if(includeTransitive) {
bringAllDependencies(targetDeps,dep,cachedEnvironmentDeps,includeTransitive)
let depArray = new Array()
// to avoid infinite loop, check if the dependency not already on current path, before going recursively resolving its dependencies.
if(!path.includes(dep.toLowerCase())) {
// send to recurrsion the path + the current dep
depArray.push(dep.toLowerCase())
if (includeTransitive) {
// send to recurrsion the array of all deps in path + the current dependency name which is not on the path.
bringAllDependencies(targetDeps, dep, cachedEnvironmentDeps, includeTransitive,path.concat(depArray))
}
}
// sort ra
targetDeps.sort((dep1,dep2) =>{
Expand Down
Loading