Remove ' from document attribute

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
kklosson
Posts: 1617
Joined: Sun Nov 23, 2008 3:19 pm
Location: Virginia

Remove ' from document attribute

Post by kklosson »

I have a feature where users upload a document. If the document name includes an apostrophe ( ' ), such as "Jim's Statement.doc", it's a legit filename in most operating systems and it uploads fine. But trying to download it results in an error. I can't figure out how to use REPLACE_PATTERN for this since I must enclose the apostrophe within apostrophes, and this doesn't seem to fly. I am also not sure if this will work on a document attribute since the document is the whole blob and I'm not sure if the replace_pattern function would be addressing the filename or the data. Perhaps I need a Java script to catch it at file selection on the client. If so, I need someone to write that for me. $$
V8.8
MySQL, AWS EC2, S3
PDFtk Toolkit
BobK
Posts: 544
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: Remove ' from document attribute

Post by BobK »

kklosson wrote:I have a feature where users upload a document. If the document name includes an apostrophe ( ' ), such as "Jim's Statement.doc", it's a legit filename in most operating systems and it uploads fine. But trying to download it results in an error. I can't figure out how to use REPLACE_PATTERN for this since I must enclose the apostrophe within apostrophes, and this doesn't seem to fly.
Try the following to remove the apostrophe:

Code: Select all

REPLACE_PATTERN(BO.Attribute, '\x27', '')
FYI: 27 is the ASCII hex code for the apostrophe(').

kklosson wrote:I am also not sure if this will work on a document attribute since the document is the whole blob and I'm not sure if the replace_pattern function would be addressing the filename or the data. Perhaps I need a Java script to catch it at file selection on the client. If so, I need someone to write that for me. $$
Can't help you here. Try it and report back your results.
Bob
kklosson
Posts: 1617
Joined: Sun Nov 23, 2008 3:19 pm
Location: Virginia

Re: Remove ' from document attribute

Post by kklosson »

REPLACE_PATTERN(FilledForm.Form, '\x27', ' ' )
This does not pass error checking when saving.
V8.8
MySQL, AWS EC2, S3
PDFtk Toolkit
hpl123
Posts: 2579
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Re: Remove ' from document attribute

Post by hpl123 »

kklosson wrote:I have a feature where users upload a document. If the document name includes an apostrophe ( ' ), such as "Jim's Statement.doc", it's a legit filename in most operating systems and it uploads fine. But trying to download it results in an error. I can't figure out how to use REPLACE_PATTERN for this since I must enclose the apostrophe within apostrophes, and this doesn't seem to fly. I am also not sure if this will work on a document attribute since the document is the whole blob and I'm not sure if the replace_pattern function would be addressing the filename or the data. Perhaps I need a Java script to catch it at file selection on the client. If so, I need someone to write that for me. $$
Try using a SystemSettings attribute where you have the ' i.e you do REPLACE_PATTERN(FilledForm.Form, SystemSettings.CharApo, ' ' ). Written ad hoc so syntax may be wrong.
Henrik (V8 Developer Ed. - Windows)
kklosson
Posts: 1617
Joined: Sun Nov 23, 2008 3:19 pm
Location: Virginia

Re: Remove ' from document attribute

Post by kklosson »

I am able to solve my problem using the RENAME DOCUMENT action. However, there remains a need to search for an apostrophe in a text string and I cannot figure out how to do it.
V8.8
MySQL, AWS EC2, S3
PDFtk Toolkit
customaware
Posts: 2391
Joined: Mon Jul 02, 2012 12:24 am
Location: Ulaanbaatar, Mongolia

Re: Remove ' from document attribute

Post by customaware »

This works for me....

MyData.CleanString=REPLACE_PATTERN(MyData.ApostString,`'`,``)
Cheers,
Mark
_________________
AwareIM 6.0, 8.7, 8.8, 9.0 , MariaDB, Windows 10, Ubuntu Linux. Theme: Default, Browser: Arc
Upcloud, Obsidian....
Image
BobK
Posts: 544
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: Remove ' from document attribute

Post by BobK »

In my original posting, I was just showing the format for the REPLACE_PATTERN function.
The complete action would be:
FilledForm.Form=REPLACE_PATTERN(FilledForm.Form, '\x27', '')

If that is what you did, what was the error you got? The above worked for me.

Mark's suggestion should also work.
Bob
kklosson
Posts: 1617
Joined: Sun Nov 23, 2008 3:19 pm
Location: Virginia

Re: Remove ' from document attribute

Post by kklosson »

Okay and thanks all. I did not realize that ` (the backward thingie under the tilde) could be used in place of ' (apostrophe). I learned something useful!
V8.8
MySQL, AWS EC2, S3
PDFtk Toolkit
kklosson
Posts: 1617
Joined: Sun Nov 23, 2008 3:19 pm
Location: Virginia

Re: Remove ' from document attribute

Post by kklosson »

I seem to still be struggling with this. I need to remove any apostrophe characters from file names added to a document attribute. FilledForm.Form represents a document attribute. Mr rule is:

FILE_NAME(FilledForm.Form)=REPLACE_PATTERN(FILE_NAME(FilledForm.Form),`'`,'')

This results in the attached validation error. has anyone roped this goat?
Attachments
Validation Error.png
Validation Error.png (7.93 KiB) Viewed 6625 times
V8.8
MySQL, AWS EC2, S3
PDFtk Toolkit
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Remove ' from document attribute

Post by Jaymer »

try using the CHR function,
or make a SystemSettings field with that character as the value
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
kklosson
Posts: 1617
Joined: Sun Nov 23, 2008 3:19 pm
Location: Virginia

Re: Remove ' from document attribute

Post by kklosson »

I ended up using the RENAME DOCUMENT action and that seems to work fine.

Thank you for responding.
V8.8
MySQL, AWS EC2, S3
PDFtk Toolkit
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Remove ' from document attribute

Post by Jaymer »

I reported a bug in the last few months, where the rename document was working, but it left the original file there. So if you rename the file A to file B, it was copying it instead of renaming it.
Can you check your physical directories and see if this is happening for you?
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Remove ' from document attribute

Post by Jaymer »

Lol
Didn't realize this was a long thread. Didn't read the prev msgs.
I also reported that if the filename had a '#' In it, it would save file but you couldn't reopen it if it was a pdf.
This might be corrected in 8.5 later builds.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
kklosson
Posts: 1617
Joined: Sun Nov 23, 2008 3:19 pm
Location: Virginia

Re: Remove ' from document attribute

Post by kklosson »

Thanks. My assessment is that apostrophe and hash symbol will fail when downloading. I tried many other characters that all work. I am storing it in the database so I don't think the duplication issue is an issue. This update rule works:

IF FILE_NAME(FilledForm.Form) CONTAINS `'` OR
FILE_NAME(FilledForm.Form) CONTAINS `#` THEN
RENAME DOCUMENT FilledForm.Form TO REPLACE_PATTERN(FILE_NAME(FilledForm.Form),`'`,'') + '.pdf'
RENAME DOCUMENT FilledForm.Form TO REPLACE_PATTERN(FILE_NAME(FilledForm.Form),`#`,'') + '.pdf'
V8.8
MySQL, AWS EC2, S3
PDFtk Toolkit
Post Reply