• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

How to handle start of header character

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

A user entered a value in a texbox...However somehow the start of the header character is embedded along with the string

However on parsing JDOM exception is thrown 0x1 is not a jdom character content

1. Will the problem will be resolved if i add trim ??
2. How to figure out whether a string has start of header character at the prefix or in the suffix and remove them ?
3. Is it good to remove the start of header character or throw exception to the user as it contains illegal character

Please kindly advise.

Thanks.
 
Sheriff
Posts: 24635
56
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would help if we knew what kind of "texbox" you were asking about. And also what a "header" is in that context.
 
Saloon Keeper
Posts: 5776
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does JDOM have to do with a user entering text - is the user supposed to enter XML? If so, is there a chance that it can be uploaded as a file instead?

What do you mean by "start of header character" - the BOM (assuming it's XML)?

It's hard to advise what to do - if the user enters an invalid character, then an error should be displayed. OTOH, it's much to ask from a user to enter valid XML, so any effort you can make to accept a wide range of common mistakes is probably a good idea.

Will the problem will be resolved if i add trim ?


That's easy to test, isn't it?
 
Marshal
Posts: 65466
249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joseph Michael wrote:. . . 1. Will the problem will be resolved if i add trim ??

Have you looked at the documentation for String#trim()? What is the value of SOH? Is it 0x0001? What will happen if they have managed to get the SOH in the middle of the text?

2. How to figure out whether a string has start of header character at the prefix or in the suffix and remove them ?

Can you use the usual methods for finding whether a String contains a particular substring or character?

3. Is it good to remove the start of header character or throw exception to the user as it contains illegal character . . .

How are your users getting an SOH into the text box in the first place? What is the risk to your program if your users insert non‑printing characters into text? If you throw an exception, how is the user going to know about it, and what are they going to do about it? How difficult would it be to remove non‑printing characters from your text?
 
Joseph Michael
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The user copies a text from excel or some where..When he pasted into the application string field or text box, SOH character gets appended.

SOH character - https://i.stack.imgur.com/sspjH.png

char(1) gets appended and causes the parse exception

Either we need to remove using trim or some function or should not allow the text at all. What would be the best approach in this case?
 
Bartender
Posts: 21004
128
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be interesting to know where "somewhere" is.

An SOH character is used in networking protocols. It should not be present in user data, since the intervening network stack layers should have completely removed framing, error checking/correction and other transmission-related data before delivering to the Presentation Layer (application).

Of course, this mar not really be SOH. It could be simple junk whose value just happened to be 0x01. Or you could be mis-reading a 2-byte Unicode sequence where the character value was actually \x01xx. But GUI controls shouldn't be delivering non-display characters to application code. Things like control keys and their relatives (RETURN, DEL) are supposed to be handled by other parts of the GUI framework, not passed as control values.

And I just noted that it said "appended". It's not a START of HEADER if it's appended!
 
Paul Clapham
Sheriff
Posts: 24635
56
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joseph Michael wrote:What would be the best approach in this case?



Presumably the user can paste any text, which might or might not be well-formed XML. You could take the approach of rejecting all inputs which are not well-formed XML... that puts the burden on the user to make sure they are only posting valid input.

On the other hand if this particular solution happens regularly you should look into the copy-paste process to find out what's going on. I can't see somebody posting an XML document from a cell in Excel and if they did I can't see it containing unprintable characters like the one you are having trouble with. Maybe there's something funny about these text boxes, which you still haven't told us what kind they are. Swing? Javascript? Something else?
 
Joseph Michael
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not a XML...Just a user alphabetical character string..Where SOH is exist in start of the string or middle of the string or in the end of the string...How to restrict this in Java? We want to support unicode however want to restrict SOH alone
 
Paul Clapham
Sheriff
Posts: 24635
56
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joseph Michael wrote:This is not a XML...Just a user alphabetical character string..Where SOH is exist in start of the string or middle of the string or in the end of the string...How to restrict this in Java?



The way to restrict it is to have your text box ignore that character. Probably... but you haven't told us what kind of text box it is so I couldn't tell you how to do that. Or you could just delete that character from wherever it appears in the strings you're getting.
 
Campbell Ritchie
Marshal
Posts: 65466
249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:. . . just delete that character . . .

...and any other non‑printing characters. Have you worked out how much of a threat such non‑printing characters pose to your program?

You will get much better answers if you supply us with all the details we have been asking about.
 
Joseph Michael
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for all your answers....What you all conveyed is right..I am going to strip out the characters so that it won't be an issue at all. It's an invalid character which should be removed. Thanks for all your time and suggestions
 
Campbell Ritchie
Marshal
Posts: 65466
249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What characters do you plan to strip out?
 
Joseph Michael
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Going to use StringUtils apache commons which will strip out all control characters which is not required in normal inputs. Is that would cause any issue?
 
Campbell Ritchie
Marshal
Posts: 65466
249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joseph Michael wrote:. . . StringUtils . . . Is that would cause any issue?

Don't know. Please supply more details.
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!