Dnn.Platform icon indicating copy to clipboard operation
Dnn.Platform copied to clipboard

Journal Link Title Url missing in link posts.

Open thabaum opened this issue 4 years ago • 23 comments

Description of bug

Posting a link to a site in the journal posts content about the site, however the link to the site is not correct when you click on it, and the link in journal does not work.

Steps to reproduce

List the steps to reproduce the behavior:

  1. Go to journal
  2. post a link to a website such as www.github.com
  3. Hover over the title (or image) and inspect the link.
  4. link created for the title (and image) is blank

Current result

The link is not being stored in the database. Link is created but no URL set in db to produce a link for a title along with the image.

Expected result

Website link posted in the journal is stored in the database to allow the journal to create the link to the website link posted.

Screenshots

If applicable, provide screenshots to help explain your problem. image

Additional Context

The URL is not being stored in the database. The database is storing everything but the URL. If posting with http://url.com or https://url.com or www.url.com will create a URL dataItem entry in the database. There will be a check that will test and set the http:// or https:// added to a www only link urls provided when detected. If only a www it will not be treated properly in DNN so it needs to add an http:// at least to the link for DNN to allow it and it to pass checks. I believe everything gets the the prefix stripped (http https) and then it gets added again later as it gets passed around. I believe somewhere along the way DNN sees any Urls as not urls by the time it gets to the test and so it stores an emty string instead.

thabaum avatar Nov 18 '19 04:11 thabaum

I can reproduce in 9.4.2

valadas avatar Nov 18 '19 08:11 valadas

Correction: Images are working I was using www.msn.com for one test and www.github.com for the other. Msn will not return an image. GitHub does.

I want to also see if I can fix an issue for the DNN Events calendar that also relates to DNN Journal so I can review both issues. https://github.com/DNNCommunity/DNN.Events/issues/40

thabaum avatar Nov 24 '19 00:11 thabaum

An update here so this does not go stale:

The journal is not saving the URL: in the database. I have read the module source code a few times and believe that I am getting warmer as to where this event happens. I think I need a better testing environment setup to really tackle things like this one.

Some odd behavior when you manually set the URL: part that is missing in the databse journal item data that I noticed:

If you have a url like www.therestoftheurl.com instead of one with http/https in front of it, the journal tries to load a page from within the site www.dnnsite.com/www.therestoftheurl.com but if you have http:// or https:// added it will link to domains off the website. I would prefer not to have either http or https and load a new browser tab with just the domain and let the web server that handles the domain put http or https on the url as need if possible?!

Maybe this might help someone come up with a solution as well. Thank you for any help and support here.

thabaum avatar Jan 05 '20 19:01 thabaum

@thabaum I have not dug into the code myself, but a guiding principle across DNN (and most other web apps) is that when storing URL field data, if it is not prefixed by https://, http:// or //, then it is not an absolute URL. It is instead assumed to be a relative URL. Therefore, the behavior being reported is actually what I would expect.

As it relates to the URL's "preview image" that is usually provided via a combination of page data and metadata:

  • Title
  • Description
  • og:title
  • og:description
  • og:url
  • og:image
  • favicon

Again, I am not sure what this code is reliant on in DNN, but it is most likely one or more of the above. The og: prefixed metadata is based on OpenGraph.

That said, is this really a bug?

david-poindexter avatar Jan 05 '20 20:01 david-poindexter

The protocol should be part of an url, an url is in fact not even for web, it could even be ftp://somedomain.com/somefolder so yeah, the protocol is definitely a needed part of any url.

valadas avatar Jan 05 '20 21:01 valadas

@valadas ultimately yes - of course. 😄

I'm just saying that DNN most likely supports relative and absolute URLs. Whether or not it should in this context is probably where the focus needs to be. I would think in this context it should only accommodate/support absolute URLs.

david-poindexter avatar Jan 05 '20 22:01 david-poindexter

Posting a "link" in the journal when you just type "www.domain.com" the post becomes a "link" datatype and so DNN journal does not know HTTP or HTTPS but still knows it is a link and then it strips things // and prior to the www I believe I seen in the code. There are a few areas that are of interest I will make references here soon maybe it can help shine light here.

DNN Journal would have to add an HTTP:// or HTTPS:// without knowing which to put I am guessing the HTTP:// would be default. I was trying to find where it adds this, i found some code that strips it and adds again. When it grabs images and description of the page it has the URL in memory so need to know why that URL is not getting set in the Database for setting the HREF= part of the Journal post.

thabaum avatar Jan 14 '20 04:01 thabaum

@david-poindexter

The bug here is the link does not work, it is blank when you post a link in a journal post. Image and description of the website works but if you click on the link created for the journal post it goes no where.

To reproduce post a link in the journal and try to click on the url that is created for a link to the website that is entered. The href="" which in the database it is not being set. I can manually add the link that is missing in the database and everything works for that post. This is when I found it the link must have HTTP:// or HTTPS:// to make the link work in the journal because when I set it to just have a domain name without those it would go to a local page on the website creating a page not found error.

This is just a clue to what needs to happen prior to setting the URL in the database is there needs to be HTTP:// added to the front of the website link for DNN Journal to allow it to work AND it is not getting set at all either way so there are two things going on here that must happen for it to work right.

  1. the www.domain.com link needs be http://www.domain.com to work
  2. the URL after it has been properly created in a variable needs to add that URL in the correct format to the database when created the post inside the journal module on a dnn page.

Some reason the url is not being posted to the database in any way, it is blank so when you click on the link created in the journal it goes no where.

This is a bug and needs some love.

I would prefer it allow a www.domain.com url without the HTTP or HTTPS and let the website it is going to figure out what is best this way when someone posts www.url.com it will just open a page with www.url.com and not worry about the http or https parts added. I understand this is by design so not much to do here now. The issue at hand is getting a URL saved in the database that is getting lost before the database entry is created.

I don't know what the url looks like that would be otherwise posted to the database to see if that is even an issue as the code may handle it as I seen some code that sets these in the url as needed. The Url information in the end is not being returned to be set in the database.

thabaum avatar Jan 14 '20 04:01 thabaum

After digging a bit further I believe I may have found the issue potentially with your help? I need to know !IsAllowedLink part of the code below is something that is getting set somehow somewhere to where it is making the ItemData.Url string empty.

Maybe the permissions of security roles that are allowed to post each different data type such as a link is missing or is there a way to set the IsAllowedLink setting somehow?

Is there a way to test this further quickly maybe by commenting those lines out below. And if there is a proper way to deal with this if there is an issue here. Thank you!

https://github.com/dnnsoftware/Dnn.Platform/blob/develop/DNN%20Platform/Modules/Journal/ServicesController.cs#L217-L221

Line: 217

  if (!IsAllowedLink(ji.ItemData.Url))
                {
                    ji.ItemData.Url = string.Empty;
                }

IsAllowedLink method is on Line 96

In the following method return statement testing if !url.Contains("//"); makes me think that if the // is stripped somehow it would not pass here as well if a www.domain.com url was not being created into one with an https:// or http:// so they have the // included in the url.

So this maybe boogering things up here too:

        private static bool IsAllowedLink(string url)
        {
            return !string.IsNullOrEmpty(url) && !url.Contains("//");
        }

I think commenting the ji check would see what is actually being created to see if it is not getting set due to no HTTP:// in front of the Url

I also think if this is the case the code here might be the right direction but probably not the right syntax which would be to add the http:// at least to the url since it might only have the www.domain.com without the HTTP:// so it does not pass the check. I am trying to understand when this check would not want to set the Url if a Url is set and why it does not handle a www, however there is another place that handles adding/removing http and // But maybe this line makes a little sense:

  if (!IsAllowedLink(ji.ItemData.Url))
                {
if (!journalTypeId=2)  {
                    ji.ItemData.Url = string.Empty;    }
else {
ji.ItemData.Url = string.("http://" + ji.ItemData.Url);   }
                }

Maybe the something that can add an http:// so it tries to make the link. I know what I wrote above would not function properly as I am just guessing here a solution if I am heading in the right direction with things maybe some more thoughts here would help from anyone.

thabaum avatar Jan 16 '20 20:01 thabaum

Keeping this from going stale, I am going to give it a go here soon pick up where I left off in the next couple weeks. This, social groups link issue and DNN Events module posts not stripping the HTML are issues related I will be hoping to address for some version 9 fixes. Thank you.

thabaum avatar Feb 26 '20 18:02 thabaum

Issue looked a little confusing. I updated the issue along with adding some additional context with things I believe may be happening here to create the issue. If you post a link in the journal the Url is not being saved to the data items in the database. So then the url is blank when the journal creates post entry to be viewed. If you add an address with Http:// or Https:// in the database manually the address appears and will work right. Link url is not getting saved to the database currently.

Possibility is the https:// and http;// get checked and if they have anything with a // it is removed. But I don't think http:// or https:// is ever added back again to the link data and then when it needs to get saved it gets checked to see if it has // but it has been removed when it was cleaned of it therefore a url is never stored it the database. A www does not have this so it fails as well getting saved. If I remember right this is what I believe is the current issue best explained I can.

The first picture is pulled from the URL and maybe this process is what strips the http and https from the url.

I am going to hopefully figure a way to step through this again and understand what is missing here. I will be giving this all another go here in the next week. I am not the most versed here so wish me luck :)

thabaum avatar Apr 07 '20 22:04 thabaum

OK just so this is not stale... my situation is getting a better environment to test for a solution for this issue. I only have so much time and resources to spend to make something happen and I have done it a few times in the past but it is a process to setup and get things running on my machine which is what has been dragging me behind here. I am a past unix, C and pascal programmer give me a brake :)... I do need to get this completed I need this to function properly. I did put some notes above talking to myself... I will review after I get down editing this part of the platform, building and debugging it. Part I have the issue with is getting the site going.

What I believe is a solution here... is steps, videos no longer than 3 minutes long. Each is a step towards setting up the environment. Everyone may have an issue with one step but you have to watch 5 20 minute to 1 hour videos and still may not get the answer to making it happen. Anyone have a link to a good relevant version of setting up DNN so you can debug the platform in a productive way? I just need an example of making a change to a file saving it and running a site to view the change. I am guessing otherwise and I think whatever I am missing everyone else takes for granted ;)

thabaum avatar May 30 '20 17:05 thabaum

Did you read the build instructions here, there are explanations for creating a full release, updating an existing development site or building for debug. Following the build instructions for debug is probably what you want and then you would put a breakpoint and attach to the w3wp process for the site and it should work. If you have problems, please let us know.

valadas avatar May 31 '20 17:05 valadas

Thank you @valadas it has been a real challenge, seems like at one time I had it all right but then just blanked on how to do it again with so much time between attempts not doing so much of this type of work daily... I really need this one source I can go back to for a refresher so I will go over it hoping with debugging instead of just thinking about how it should work... reading code hoping this week.

Once I get this solution doctored up I can start helping with .NET Core transitions better with a clearer understanding from working with Oqtane, thank you @david-poindexter for pointing that out I wanted to get into cutting edge era web development with Blazor and .NET Core in a project that shared a similar philosophy to DNN. Both serve little different purposes for web projects and I want to help as I can as you all have helped me, I want to return the favor down the road.

I will get back with any questions I have along the way. It would be fun to get into debugging this in a pro-efficient way... and I think I just need to practice doing it for a while a lot. I am getting warmer to VS and GitHub so that helps not having that frustration on top of this bug :)

Thanks again, you all are awesome!

thabaum avatar Jun 20 '20 18:06 thabaum

https://github.com/dnnsoftware/Dnn.Platform/blob/develop/.github/BUILD.md

That is the link to get environment setup,

I found my problem, I never knew what Cake was... I always wondered and figured it had to do with things that it did but nothing about actually configuring it for my environment.

This unpacks the web files so I can see changes, this was my missing link.

missingLink == Cake;

output true

thabaum avatar Jun 20 '20 18:06 thabaum

I am going to do a recap here soon as I set up hoping this week get somewhere on this issue.

thabaum avatar Sep 09 '20 00:09 thabaum

OK, its cold again... I am going to give this a go!

thabaum avatar Dec 08 '21 01:12 thabaum

Line 422

                if (!IsAllowedLink(ji.ItemData.Url))
                {
                    //ji.ItemData.Url = string.Empty;
                }

I commented out the entire if statement and the website Url and ItemData information was not submitted to the database. I commented out just the line 422 inside the if statement as shown above and it the links work!

What should we do here to make this right. I found a solution, delete this one line. But the if statement has to stay here or the url is never submitted to the database array information for ItemData

Make Sense? I want to submit a PR but I dont think I have this 100% yet. Any input on what should be done here to make it a success!

thabaum avatar Dec 08 '21 06:12 thabaum

image You can see at the bottom of page of screen snippet I was hovering over the last github.com link, and it works :) but I am not sure I feel confident just deleting this line is correct.

A lot of elements need documented in these files I can put these into a PR while I am browsing around if I can get a grip on that. Fix as many little things as possible to clean up the build.

For this PR to resolve this issue, I just want to grasp what the point of this one line is. I feel like it is missing something, like a check for something dangerous but can't put my finger on it. It does so many checks in other places. I went through all the JS, DB and CS files chasing an answer trying to understand the logic here.

@bdukes or @valadas got any ideas? Sorry to bother but I would like to get this in next release if I can. This is the bonus for helping me out earlier, links working in DNN Journal!

thabaum avatar Dec 08 '21 06:12 thabaum

Line 318

        private static bool IsAllowedLink(string url)
        {
            return !string.IsNullOrEmpty(url) && !url.Contains("//");
        }

If you are posting a Url, Of coarse it will have "//" in an address like http://domain.com. // is used in more than just HTTP and HTTPS.

return !string.IsNullOrEmpty(url) && !url.Contains("//"); I was thinking changing to return !string.IsNullOrEmpty(url) && url.Contains("//");

Tomorrow see what breaks.

Another issue is it puts HTTP instead of HTTPS, however most sites forward to HTTPS I entered HTTPS site and the database stored it as HTTP, What you enter is what should be entered into the database. Related to this issue

I remember seeing some logic like that I believe in the js file.

This IsAllowedLink function needs updated or remove the line 422?

Food for thought for tomorrow.

thabaum avatar Dec 08 '21 06:12 thabaum

what is funny... github makes a link out of a www in places, I felt DNN Journal was going to be a little better having www.

thabaum avatar Dec 09 '21 00:12 thabaum

I double tested this solution and seems to resolve things just fine. I like how it helps the ease of extending future features with journal input as well. Thank you all for reviewing this.

thabaum avatar Dec 11 '21 23:12 thabaum

For what its worth, you can use this javascript/jquery to make the links clickable. More a patch however, If the users was to delete the actual link text before posting it won't work.

	var targetDiv = document.querySelectorAll("[id^='jid-'] .journalitem p:first-child");
	for(var i=0; i<targetDiv.length;i++){
		
		var sumbittedUrls = $(targetDiv[i]).text();
	  	var urls = sumbittedUrls.match(/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/);

		if($(targetDiv[i]).parent().find('.jlink a').length !== 0) {
	  		$(targetDiv[i]).parent().find('.jlink a').attr('href', urls[0]);	  

			$('.journalitem p:contains('+(urls[0])+')').each(function(){
				$(this).html($(this).html().split(urls[0]).join(""));
			});
			
		}

	}

dustinp26 avatar Jan 21 '22 17:01 dustinp26