How can I insert a double quote in the session relevance - relevance

target fixlet name = abcdef"123"
Then how can I use the session relevance to get the record?
Name of fixlet contains "abcdef"123"" << doesn't work.
BTW DONT TRY TO EDIT ANYMORE, THIS IS NOT RELEVANT TO JAVA
IF YOU DONT KNOW WHAT IS SESSION RELEVANCE, PLEASE JUST SKIP THIS.

IBM relevance
Since you are outputting to the Web as HTML I guess you have to encode them into UTF-8.
Double quote is %22, according to Wikipedia, so try: "adcdef%22123%22"

Have you tried escaping quotes with backslash?

Related

(iOS) Escaping single quote in XML

I have written the below code in xml:
var invalidLastNameMessage="We&apos;re sorry, but that last name doesn&apos;t match our records.";
When i check in IOS devices(ipod/iphone), it should come like:
We're sorry, but that last name doesn't match our records.
But it shows like :
We&apos;re sorry, but that last name doesn&apos;t match our records.
Can anyone explains that why was it happened?
I would not be surprised if it automatically is escaped. It seems like it escapes
We&apos;re
to
We&apos;apos;re
Did you try just feeding it a non-escaped value?

RESTful url in android with (')

I am developing an android application and I am using a RESTful service to connect to SQL azure database. I need to use this RESTful url:
http://example.com/wcfDataService1.svc/wn_synset?$filter=word%20eq%20'child's_game'&$select=synset_id,w_num,word,ss_type,wn_gloss/gloss&$expand=wn_gloss
As you can see am looking for this word (child's_game) in the table wn_synset.
The problem is the single quote (') in child's_game. As you can see it puts the word inside quotes '...' so when it finds the quote in child's_game it thinks it is the end of the word and the rest is error.
How can i solve this problem?
You can url-encode the ' symbols with %27. See http://www.w3schools.com/tags/ref_urlencode.asp and try it in the "Try it yourself" section.
Edit: (moved correct guess from comments to the answer itself)
Or is it just, that the SQL-Server on the server side gets it wrong? Like it builds a select * from wn_synset where word = 'child's game' and there's the error? Then you'll have to look up how you escape single quotes for your database -- probably it's by using two single quotes (''), so perhaps try to send child''s game instead of child's game.
There is no problem, or in other words, your URL is not a URL. If it were a URL, ther wouldn't be a '. Of course, you can have this ' in your URL, so to speak. But it needs to be escaped in accordance with the rules for URLs. You may want to look at URLEncoder and Uri.

What is the proper way to sanitize user input when using a Ruby system call?

I have a Ruby on Rails Application that is using the X virtual framebuffer along with another program to grab images from the web. I have structured my command as shown below:
xvfb-run --server-args=-screen 0 1024x768x24 /my/c++/app #{user_provided_url}
What is the best way to make this call in rails with the maximum amount of safety from user input?
You probably don't need to sanitize this input in rails. If it's a URL and it's in a string format then it already has properly escaped characters to be passed as a URL to a Net::HTTP call. That said, you could write a regular expression to check that the URL looks valid. You could also do the following to make sure that the URL is parse-able:
uri = URI.parse(user_provided_url)
You can then query the object for it's relevant parts:
uri.path
uri.host
uri.port
Maybe I'm wrong, but why don't you just make sure that the string given is really an URL (URI::parse), surround it with single quotes and escape any single quote (') character that appears inside?

Find all URL's in a string in rails 3

I'm building an app in Rails 3 and I need a method to extract all urls from a string and store them in a hash or something. I know I need to use regular expressions but I don't know where exactly to begin with them.
Also, I know about auto_link, but it doesn't quite do what I'm trying to achieve. I just simply need a hash of all the url's from a string.
Thanks!
From http://www.regular-expressions.info/ruby.html
"To collect all regex matches in a string into an array, pass the regexp object to the string's scan() method, e.g.: myarray = mystring.scan(/regex/)."
So you probably need strings that start with "http". So check the docs for that :)
I don't program in Ruby and I'm not very good with regex but maybe this will help you out:
http://www.ozzu.com/programming-forum/url-regex-t104809.html

Regular expression not working when put in an object

I'm trying to store regexes in a database but they're not working when used in a .sub(), even though the same regex works when used directly in .sub() as a string.
regex = Class.object.field // Class.object is an active record containing "\w*\s\/\s"
mystring = "first / second"
mystring.sub(/#{regex}/, '')
// => nil
mystring.sub(/\w*\s\/\s/, '')
// => second
Any insight appreciated!
Thanks,
Matt.
Editing to correct class/object terminology (thanks) & correcting my 2nd example as I had shown #{} wrapped around the working regex (cut & paste SNAFU).
To answer your question: It is not quite what kind of thing your Class.object is. If it's an ActiveRecord, it won't work.
Edit: You obviously found that the problem is Rails escaping the regexp.
An ActiveRecord cannot "contain" your regular expression directly; the regexp will be in one of the fields of your record. In which case you'd want to do something like regexp = Class.object.field_containing_the_regexp.
Even if that is not the case, I suspect that the problem is that your regexp is something other than a string. You can quickly test this by using
puts "My regexp: #{regexp}"
The string that you will see in the output will be the one that is used for the regexp.
A String is not a Regexp. You have to create a Regexp object first.
regex = Regexp.new("\w*\s\/\s")
Turns out my regexp didn't cater for all cases - \w didn't account for symbols. After checking in rails console, and seeing the screwey escaping I was alreasdy half-way down the wrong track.
Thanks for the help.

Resources