I am trying to read and save a json file. The problem is that when I call write_json(pt, "newFile.json") it is changing the content of some fields like:
input:
"field1":"path/to/file.txt"
is changed to:
"field1":"path\/to\/file.txt"
Is this a bug? How to fix it?
It means it escapes the forward slash. The JSON spec says you can escape forward slash, but it's not mandatory. As for the reason, here is a good explanation.
Related
I need a trailing comment in my code. Sonar keeps throwing this error. Unlike the public version, our Sonar says there is a way around this...
Parameters
legalCommentPattern
Pattern for text of trailing comments that are allowed.
Default Value:
^//\s*+[^\s]++$
This seems to suggest there is a way to add a comment to the EOL (which I need to do) but playing around in Regex pal I can't seem to figure it out.
How do I add a trailing comment that meets the legalCommentPattern. Or how do I change the value to allow for inline shorter comments.
I'm trying to open a file in Qt.I used double back slash in this function
doc->dynamicCall("Open(QVariant)", "E:\\QT\\build-untitled-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug\\My Question.doc")
and it works. However, my directory variable's absolute path returns this, which has forward slash:
"E:/QT/build-untitled-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug/My Question.doc"
and It doesn't work. Error says: " Sorry, we couldn't find your file. Is it possible it was moved, renamed or deleted?" I tried everything and it only works with double back slash.
I do know that I have to escape \ as \\, but how do I write this function using my variable ?
I think toNativeSeparators function may help you. Since you are on Windows it will replace forward slashes into backward slashes.
Code is like that:
string path = "E:/QT/build-untitled-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug/My Question.doc";
doc->dynamicCall("Open(QVariant)", QDir::toNativeSeparators(path));
Working on one of the tasks i am using jsstringformat function to handle json data if some special characters are used, but that does not seems to handle all issues.
My JSON still breaks.
I am using like this :
"<a href='edit.cfm?id=#jsStringFormat(qFiltered.randomnumber)#' style='color:##066D99'>#trim(jsStringFormat(qFiltered[thisColumn][qFiltered.currentRow]))#</a>"
I am lost here what else i can use as any part of regex or rereplace that it should not break
Thanks
You're doing multiple things here.
You're putting the string into a URL: use UrlEncodedFormat.
You're also putting it in an HTML tag: use HtmlEditFormat.
The whole thing is going into a JavaScript variable, so I would use JSStringFormat to wrap the whole thing.
Try building your string before assigning it.
<cfsavecontent variable="htmlLink"><cfoutput>
#HtmlEditFormat(Trim(qFiltered[thisColumn][qFiltered.currentRow]))#
</cfoutput></cfsavecontent>
myJsVar = "#JsStringFormat(Trim(htmlLink))#";
I am working on IDML files which are used by InDesign. I am facing a problem in inserting a special instruction. I need to embed RightIndentTab with IDML file. The unicode for the same is U+0008. When I try to add that it throws error as this unicode is not supported in XML specs.
I looked more into it and IDML has a special Processing Instruction which can be inserted it looks like now the problem is when I add this it introduces a line break before the RightIndent symbol. On debugging I found that the content element looks like
<Content>
<?ACE 8?>9731396</Content>
It is an XElement and I see \r\n when I call ToString() on it. I also tried using XmlWriter.
What I would like is an XElement object which looks like
<Content><?ACE 8?>9731396</Content>
Thanks in advanced!
I've encountered exactly the same problem adding processing instructions to IDML, using .NET. Even with significant whitespace turned off I got a line break that InDesign treats as part of the text.
The only solution I have found is to save the file as XML, then open it as a text document and use a regular expression to replace >\r\n<? with just ><?. It's ugly and kludgy, but it does work - I don't have the regex to hand but you should be able to figure it out fairly quickly.
I've never had any problems adding unicode chars to XML, though. I would just use and also set the XmlWriter encoding to use unicode. See here for an example: http://bytes.com/topic/net/answers/176665-how-write-unicode-using-xmlwriter which recommends:
XmlTextWriter myWriter = new XmlTextWriter( fileStream,
new System.Text.UnicodeEncoding( false, false) );
I'm using a WYSIWYG to allow users to format text. This is the error-causing text:
<p><span style="line-height: 115%">This text starts with a 'T'</span></p>
The error is that the 'T' in "This", or whatever the first letter happens to be, is randomly removed when using URLDecode and saving to the DB. Removing URLDecode on the server side seems to fix it without any negative side-effects (the DB contains the same information).
The documentation says that
Query strings in HTTP are always URL-encoded.
Is this really the case? If so, why doesn't removing URLDecode seem to mess everything up?
So two questions:
Why is URLDecode causing the first text character to be removed like this (it seems to only happen when the line-height property is present)?
Do I really need (or would I even want) to use URLDecode before putting POSTed data into the database?
Edit: I made a test page to echo back the decoded text, and URLDecode is definitely removing that character, but I have no idea why.
I believe decoding is done automatically when form scope is populated. That's why characters after % (this char is used for encoding) are removed -- you are trying to decode the string second time.
For security reasons you might be interested in stripping script tags, or even cleaning up HTML using white-list. Try to search in CFLib.org for applicable functions.