STAR TREK 2d20
  1. #1

    removeEffect does not escape magic characters

    removeEffect in manager_effect.lua does not escape magic characters

    Code:
    function removeEffect(nodeCTEntry, sEffPatternToRemove)
    	if not sEffPatternToRemove then
    		return;
    	end
    	for _,nodeEffect in pairs(DB.getChildren(nodeCTEntry, "effects")) do
    		if DB.getValue(nodeEffect, "label", ""):match(sEffPatternToRemove) then
    			nodeEffect.delete();
    			return;
    		end
    	end
    end
    To fix this, simply substitute escapes prior to the use of string:match. This has been around for a very long time, i'm surprised it wasn't caught.

    Code:
    function removeEffect(nodeCTEntry, sEffPatternToRemove)
    	if not sEffPatternToRemove then
    		return;
    	end
    	for _,nodeEffect in pairs(DB.getChildren(nodeCTEntry, "effects")) do
    		if DB.getValue(nodeEffect, "label", ""):match(escMagic(sEffPatternToRemove)) then
    			nodeEffect.delete();
    			return;
    		end
    	end
    end
    
    --[[
    	Escape magic characters
    ]]--
    function escMagic(str)
    	if not str then return; end
    	str = str:gsub('%(','%%('); 
    	str = str:gsub('%)','%%)'); 
    	str = str:gsub('%.','%%.'); 
    	str = str:gsub('%+','%%+'); 
    	str = str:gsub('%-','%%-'); 
    	str = str:gsub('%*','%%*'); 
    	str = str:gsub('%?','%%?'); 
    	str = str:gsub('%[','%%['); 
    	str = str:gsub('%^','%%^'); 
    	str = str:gsub('%$','%%$'); 
    	return str; 
    end
    Reason this is relevant: flat-footed would not be removed on duplicate detection as it contains a hyphen and would never be matched. This is also applicable to other rule-sets that have magic characters in effect labels.
    Last edited by Ken L; January 12th, 2018 at 23:36.

  2. #2
    Most effects added/removed often do not have any special characters, so I'm not surprised this hasn't been an issue. I can't think of any off the top of my head other than "Flat-footed" in the 3.5E ruleset.

    JPG

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
DICE PACKS BUNDLE

Log in

Log in