quotes

How can I properly escape JavaScript in JavaScript?

折月煮酒 提交于 2019-12-04 04:51:44
问题 This might be something I can't do but... parent.document.getElementById('<?php echo $_GET['song']; ?>') .innerHTML = '<img src="heart.png" onmouseover="heartOver('');" >'; The onmouseover="heartOver(''); portion breaks my JavaScript. Is there a way to escape the quotes so I can do this? 回答1: Escape nested quotes with a backslash: \' Also, never echo user data without validating or sanitizing it: $song = $_GET['song']; // Validate HTML id (http://www.w3.org/TR/REC-html40/types.html#type-name)

Escaping quotes from Rails Variables when using them for Javascript?

拈花ヽ惹草 提交于 2019-12-04 01:01:11
I am having problems when trying to use a rails variable within javascript code. For example, I might define a link_to_remote, with parameter :complete => "alert('my_var');" If my_var = "I'm testing." , then the javascript code will break due to the single quote closing the code prematurely. If I try using escape_javascript(my_var) so that the quote gets turned into \' , it doesn't seem to fix the problem. I've noticed that when you try alert('I\'m testing'); there's a problem, but if you do alert('I\\'m testing') , it works. Since escape_javascript only turns ' into \' , rather than \\' ,

How does Google Closure Compiler handle quotes (string literals)?

 ̄綄美尐妖づ 提交于 2019-12-03 22:10:21
问题 The question 'How does Google Closure Compiler handle quotes (string literals)?' could also be re-phrased like: Why does Closure replace/swap single quotes with double quotes? How does Closure decide what quote- formatting/style to use? (How) can I change this (default) behavior? Note 1: this question is not about why Closure (or some other minifiers) have chosen to prefer double quotes (as is asked here and here). Note 2: this question is not about single vs double quote discussions, however

Django. Use url tags inside quotes, inside quotes

陌路散爱 提交于 2019-12-03 21:04:47
I want to pass this variable to the context and render it, it includes html tags. notificacion_string = "<a href = \"{% url \'perfiles:perfil\' actor.usuario.username \'recientes\' %}\" > %s </a> voted on your post" % (notificacion.actor.usuario.username) As you can see, I have tried escaping the quotes inside the href=" ". But I get this error: %u format: a number is required, not unicode So, I guess the error happens when "% url .." %() is evaluated. I have tried many things without success. Extra information: The url "pefiles:perfil" recieves two arguments: url(r'^(?P<username>\w+)/(?P

python's shlex alternative for C/C++ [closed]

…衆ロ難τιáo~ 提交于 2019-12-03 20:45:37
Simple question - is there something like python's shlex package that would allow me to simply parse/split/quote/escape shell-like quoted/backslashed strings in C or (possibly) C++? The shlex package is just wonderful with its purpose (giving easy births to minilanguages and stuff), having similar common processing tool in C would be nice. Link to shlex docs: http://docs.python.org/3.4/library/shlex.html Example of what shlex does: >>> import shlex >>> shlex.split('abc ab\\ c "ab\\"cd" key="\\"val\\""') ['abc', 'ab c', 'ab"cd', 'key="val"'] 来源: https://stackoverflow.com/questions/21959706

Python shlex.split(), ignore single quotes

删除回忆录丶 提交于 2019-12-03 17:25:17
问题 How, in Python, can I use shlex.split() or similar to split strings, preserving only double quotes? For example, if the input is "hello, world" is what 'i say' then the output would be ["hello, world", "is", "what", "'i", "say'"] . 回答1: import shlex def newSplit(value): lex = shlex.shlex(value) lex.quotes = '"' lex.whitespace_split = True lex.commenters = '' return list(lex) print newSplit('''This string has "some double quotes" and 'some single quotes'.''') 回答2: You can use shlex.quotes to

Should I use single or double quotes in my .vimrc file?

江枫思渺然 提交于 2019-12-03 16:06:34
问题 What’s the difference between single ( ' ) and double ( " ) quotes in Vim? Does it make speed differences? Is it better to use one or another when running functions inside it? Does it matter at all? I’m interested specifically in their use in the .vimrc file. I’m asking because I find people use both in the same thing, and I’m wondering what are the differences. I tried to Google this, but wasn’t able to find anything. 回答1: Double quotes allow for interpolation whereas single quotes do not.

How to handle a closing parenthesis in path names in a for loop?

ⅰ亾dé卋堺 提交于 2019-12-03 15:56:55
I have a long path name to a program I must run in a for /f loop, which includes a closing parenthesis ")", and from which I need to parse the output: for /f "tokens=1" %%G in ('"C:\Documents and Settings\myaccount\Desktop\Test_release (x86)\program.exe" list') do (echo Will do something with %%G) ...where 'list' is a parameter passed to my program. I get the error "'C:\Documents' is not recognized as an internal or external command, operable program or batch file." I do know the problem is that the closing parenthesis in fact closes the "for" block, so the ending double quotes is not "seen",

How can one turn regular quotes (i.e. ', ") into LaTeX/TeX quotes (i.e. `', ``'')

淺唱寂寞╮ 提交于 2019-12-03 13:43:02
问题 Given a document written with normal quotes, e.g. Ben said "buttons, dear sir". I replied "Did you say 'buttons'?" to him. What ways can one turn these sort of things into LaTeX quotes, with the appropriate semantics. i.e. Ben said ``buttons, dear sir''. I replied ``Did you say `buttons'?'' to him. So that LaTeX produces: Ben said “buttons, dear sir”. I replied “Did you say ‘buttons’?” My first thought is to turn to a regex. However, I'm not getting any hits from Google or the regex libraries

Using python csv writer without quotations

喜你入骨 提交于 2019-12-03 12:32:26
I'm trying to write a list of strings like below to a file separated by the given delimiter. res = [u'123', u'hello world'] When I try splitting by TAB like below it gives me the correctly formatted string. writer = csv.writer(sys.stdout, delimiter="\t") writer.writerow(res) gives --> 123 hello world But when I try to split by space using delimiter=" " , it gives me the space but with quotation marks like below. 123 "hello world" How do I remove quotation marks. So that when I use space as the delimiter I should get 123 hello world . EIDT : when I try using the escapechar it doesn't make any