Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match.content() returns owner tag name if content contains newlines #116

Closed
lukaseder opened this issue Jun 21, 2013 · 8 comments
Closed

Comments

@lukaseder
Copy link
Member

XML = 
  <x>a
  b
  c</x>

$(doc).find("x").content() returns a string including <x>..</x>. When it should return only a b c. It works like this:

XML = 
  <x>a b c</x>

$(doc).find("x").content() returns a b c
@MartyTremblay
Copy link

Awesome library! Saving me tons of time with manipulating XML.

I'm now encountering this issue. Is there a workaround?

Here's my exact use case:

<Datum ID="Image-Collection" Type="DCR" Name="Image-Collection" Label="Select an image collection:" Changed="true">
  <DCR Category="Site" Type="Image Collection">Site/Image Collection/data/awesome-images</DCR>
</Datum>
$(doc).find("Datum").content(); // returns the full <Datum> tag

running 1.3.0

@MartyTremblay
Copy link

I may have found the culprit but cannot fork to test due to limitations with my work environment. The regular expression may require the Pattern.DOTALL flag "(?s)". Can someone test?

In Imp on line #~1454:

private final String content(Element element)
return Util.toString(element).replaceAll("(?s)^<" + name + "(?:[^>]*)>(.*)</" + name + ">$", "$1");

MartyTremblay pushed a commit to MartyTremblay/jOOX that referenced this issue Apr 21, 2015
A test to see if Pattern.DOTALL fixes issue jOOQ#116
@MartyTremblay
Copy link

Just created a pull request with the change. (fyi, this hasn't been tested)

@MartyTremblay
Copy link

Short of being able to build and test, I tried this.
http://fiddle.re/ncumd6 - (http://www.regexplanet.com)

@lukaseder
Copy link
Member Author

THanks a lot for your feedback. Will have a look by tomorrow

@lukaseder
Copy link
Member Author

Spot on. Your suggestion fixes this issue. Thanks a lot for looking into this

@MartyTremblay
Copy link

Woot! Thank you for being expeditious. I will test later today.

@MartyTremblay
Copy link

I'm afraid that there is still a problem 😕. Although your unit test works, I'm getting strange results with my real-world doc. I'll try to provide you with an example but I'm required to cleanse the doc before posting it. stay tuned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants