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

Add regex check to gates and e2 find #3023

Merged
merged 1 commit into from
Mar 30, 2024
Merged
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
17 changes: 17 additions & 0 deletions lua/entities/gmod_wire_expression2/core/find.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
return string.match( string.Replace(a,"-","__"), string.Replace(b,"-","__") )
end

-- String used to check regex complexities
local sample_string = string.rep(" ", 40)

-- -- some generic filter criteria -- --

local function filter_all() return true end
Expand Down Expand Up @@ -328,7 +331,7 @@
return self:throw("You cannot send a new find request yet!", true)
end
end
return (self.data.findcount < 1)

Check warning on line 334 in lua/entities/gmod_wire_expression2/core/find.lua

View workflow job for this annotation

GitHub Actions / lint

"Unnecessary parentheses"

Unnecessary parentheses
end

-- Adds to the available find calls
Expand Down Expand Up @@ -516,12 +519,14 @@

--- Exclude entities with this model (or partial model name) from future finds
e2function void findExcludeModel(string model)
if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", nil) end

Check warning on line 522 in lua/entities/gmod_wire_expression2/core/find.lua

View workflow job for this annotation

GitHub Actions / lint

"Trailing whitespace"

Trailing whitespace
self.data.find.bl_model[string.lower(model)] = true
invalidate_filters(self)
end

--- Exclude entities with this class (or partial class name) from future finds
e2function void findExcludeClass(string class)
if not pcall(WireLib.CheckRegex, sample_string, class) then return self:throw("Search string too complex!", nil) end
self.data.find.bl_class[string.lower(class)] = true
invalidate_filters(self)
end
Expand Down Expand Up @@ -574,12 +579,14 @@

--- Remove entities with this model (or partial model name) from the blacklist
e2function void findAllowModel(string model)
if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", nil) end
self.data.find.bl_model[string.lower(model)] = nil
invalidate_filters(self)
end

--- Remove entities with this class (or partial class name) from the blacklist
e2function void findAllowClass(string class)
if not pcall(WireLib.CheckRegex, sample_string, class) then return self:throw("Search string too complex!", nil) end
self.data.find.bl_class[string.lower(class)] = nil
invalidate_filters(self)
end
Expand Down Expand Up @@ -632,12 +639,14 @@

--- Include entities with this model (or partial model name) in future finds, and remove others not in the whitelist
e2function void findIncludeModel(string model)
if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", nil) end
self.data.find.wl_model[string.lower(model)] = true
invalidate_filters(self)
end

--- Include entities with this class (or partial class name) in future finds, and remove others not in the whitelist
e2function void findIncludeClass(string class)
if not pcall(WireLib.CheckRegex, sample_string, class) then return self:throw("Search string too complex!", nil) end
self.data.find.wl_class[string.lower(class)] = true
invalidate_filters(self)
end
Expand Down Expand Up @@ -690,12 +699,14 @@

--- Remove entities with this model (or partial model name) from the whitelist
e2function void findDisallowModel(string model)
if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", nil) end
self.data.find.wl_model[string.lower(model)] = nil
invalidate_filters(self)
end

--- Remove entities with this class (or partial class name) from the whitelist
e2function void findDisallowClass(string class)
if not pcall(WireLib.CheckRegex, sample_string, class) then return self:throw("Search string too complex!", nil) end
self.data.find.wl_class[string.lower(class)] = nil
invalidate_filters(self)
end
Expand Down Expand Up @@ -865,49 +876,55 @@

--- Filters the list of entities by removing all entities that are NOT of this class
e2function number findClipToClass(string class)
if not pcall(WireLib.CheckRegex, sample_string, class) then return self:throw("Search string too complex!", 0) end
class = string.lower(class)
return applyClip(self, function(ent)
if !IsValid(ent) then return false end

Check warning on line 882 in lua/entities/gmod_wire_expression2/core/find.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of '!' and 'not'
return replace_match(string.lower(ent:GetClass()), class)
end)
end

--- Filters the list of entities by removing all entities that are of this class
e2function number findClipFromClass(string class)
if not pcall(WireLib.CheckRegex, sample_string, class) then return self:throw("Search string too complex!", 0) end
return applyClip(self, function(ent)
if !IsValid(ent) then return false end

Check warning on line 891 in lua/entities/gmod_wire_expression2/core/find.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of '!' and 'not'
return not replace_match(string.lower(ent:GetClass()), class)
end)
end

--- Filters the list of entities by removing all entities that do NOT have this model
e2function number findClipToModel(string model)
if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", 0) end
return applyClip(self, function(ent)
if !IsValid(ent) then return false end

Check warning on line 900 in lua/entities/gmod_wire_expression2/core/find.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of '!' and 'not'
return replace_match(string.lower(ent:GetModel() or ""), model)
end)
end

--- Filters the list of entities by removing all entities that do have this model
e2function number findClipFromModel(string model)
if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", 0) end
return applyClip(self, function(ent)
if !IsValid(ent) then return false end

Check warning on line 909 in lua/entities/gmod_wire_expression2/core/find.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of '!' and 'not'
return not replace_match(string.lower(ent:GetModel() or ""), model)
end)
end

--- Filters the list of entities by removing all entities that do NOT have this name
e2function number findClipToName(string name)
if not pcall(WireLib.CheckRegex, sample_string, name) then return self:throw("Search string too complex!", 0) end
return applyClip(self, function(ent)
if !IsValid(ent) then return false end

Check warning on line 918 in lua/entities/gmod_wire_expression2/core/find.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of '!' and 'not'
return replace_match(string.lower(ent:GetName()), name)
end)
end

--- Filters the list of entities by removing all entities that do have this name
e2function number findClipFromName(string name)
if not pcall(WireLib.CheckRegex, sample_string, name) then return self:throw("Search string too complex!", 0) end
return applyClip(self, function(ent)
if !IsValid(ent) then return false end

Check warning on line 927 in lua/entities/gmod_wire_expression2/core/find.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of '!' and 'not'
return not replace_match(string.lower(ent:GetName()), name)
end)
end
Expand Down
1 change: 1 addition & 0 deletions lua/wire/gates/string.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
if not B then B = "" end
if not C then C = "" end
if #A + #B + #C > MAX_LEN then return false end
if not pcall(WireLib.CheckRegex, A, B) then return false end
return string.gsub(A,B,C)
end,
label = function(Out, A, B, C)
Expand Down Expand Up @@ -343,10 +344,10 @@
if (Address == 0) then --Clk
if (gate.stringChanged) then return 1 else return 0 end
elseif (Address == 1) then --String length
return #(gate.currentString)

Check warning on line 347 in lua/wire/gates/string.lua

View workflow job for this annotation

GitHub Actions / lint

"Unnecessary parentheses"

Unnecessary parentheses
else --Return string bytes
local index = Address - 1
if (index > #(gate.currentString)) then -- Check whether requested address is outside the string

Check warning on line 350 in lua/wire/gates/string.lua

View workflow job for this annotation

GitHub Actions / lint

"Unnecessary parentheses"

Unnecessary parentheses
return 0
else
return string.byte(gate.currentString, index)
Expand Down
Loading