Jump to content

Sanitizing commas from selector


Orkun
 Share

Recommended Posts

My Code:

$lpTitle = strip_tags($thisActivity->Location['name']);
$lp = $this->sanitizer->selectorValue($this->pages->get("template=location, title=$lpTitle"));

I get this notice:

Notice: Trying to get property of non-object in /blabla/blabla/blablabla/site/modules/ProcessXMLImport/ProcessXMLImport.module.php on line 247 Notice: 

What I am Doing wrong?

Link to comment
Share on other sites

I am not sure that I understand what you are trying to achieve. Why do you want to sanitize $this->pages->get("template=location, title=$lpTitle")? It is not a user input and will return a Page or NullPage anyway. No commas ???.

If you need to get the id just use $this->pages->get("template=location, title=$lpTitle")->id.

The notice you are getting is from ProcessXMLImport module and is not directly connected with the code you presented.

Link to comment
Share on other sites

Sorry for the slurred declaration of my problem.

It has worked for me this way:

foreach ($Import->xpath('Activities/Activity') as $Activity) {

       $thisActivity = $Activity->ActivityDetail;

       $lpTitle = strip_tags($thisActivity->Location['name']);
					
       $lp = $this->pages->get("template=location, title='$lpTitle'");
       
       if(!$lp->id){
       // if not found create new page
         $lp = new Page();
         ...
       }
}

$lpTitle is a name attribute from the Location node which comes from the xml-feed. And the Problem was that the name attribute had commas inside his value and this had break the selector string. I solve this Problem by wrapping $lpTitle inside apostrophes .

  • Like 1
Link to comment
Share on other sites

From the docs:

$sanitizer->selectorValue($value)

Sanitizes a string that needs to appear in a selector value. Replaces disallowed characters with spaces. If value is not already quoted, it will add quotes if it determines they are necessary (like if it contains commas). It limits the length to 100 characters (multibyte safe).
  • Like 1
Link to comment
Share on other sites

To add to Martijn answer. This sanitizer is meant to sanitize a single selector value, not even a whole selector string, e.g.

$mytitlewithcomma = "Hamburg, the great harbour city";

// Will fail
$pages->get("title=$mytitlewithcomma");

// Won't fail
$sanitized = $sanitizer->selectorValue($mytitlewithcomma);
$pages->get("title=$sanitized");
  • Like 5
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...