user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH 0/3] a few minor small fixes
@ 2016-01-09  9:45 Eric Wong
  2016-01-09  9:45 ` [PATCH 1/3] hval: use more appropriate hvals for documentation Eric Wong
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Eric Wong @ 2016-01-09  9:45 UTC (permalink / raw)
  To: meta

3 changes:
      hval: use more appropriate hvals for documentation
      hval: new should not strip leading spaces
      view: fix Atom feed link in full message view page

 lib/PublicInbox/ExtMsg.pm     |  2 +-
 lib/PublicInbox/Hval.pm       |  3 +--
 lib/PublicInbox/SearchView.pm |  2 +-
 lib/PublicInbox/View.pm       | 29 ++++++++++++++++++++---------
 4 files changed, 23 insertions(+), 13 deletions(-)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] hval: use more appropriate hvals for documentation
  2016-01-09  9:45 [PATCH 0/3] a few minor small fixes Eric Wong
@ 2016-01-09  9:45 ` Eric Wong
  2016-01-09  9:45 ` [PATCH 2/3] hval: new should not strip leading spaces Eric Wong
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2016-01-09  9:45 UTC (permalink / raw)
  To: meta

Not needed, but this is good documentation.  Some of these values
should never have newlines.
---
 lib/PublicInbox/ExtMsg.pm     | 2 +-
 lib/PublicInbox/SearchView.pm | 2 +-
 lib/PublicInbox/View.pm       | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm
index a56df33..98da45c 100644
--- a/lib/PublicInbox/ExtMsg.pm
+++ b/lib/PublicInbox/ExtMsg.pm
@@ -124,7 +124,7 @@ again:
 		foreach my $pfx (@partial) {
 			my $u = $pfx->{url};
 			foreach my $m (@{$pfx->{res}}) {
-				my $p = PublicInbox::Hval->new($m);
+				my $p = PublicInbox::Hval->new_msgid($m);
 				my $r = $p->as_href;
 				my $t = $p->as_html;
 				$s .= qq{<a\nhref="$u/$r/">$u/$t/</a>\n};
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index b3ddcb5..8f61b4f 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -288,7 +288,7 @@ sub qs_html {
 		$self = $tmp;
 	}
 
-	my $q = PublicInbox::Hval->new($self->{q})->as_href;
+	my $q = PublicInbox::Hval->new_oneline($self->{q})->as_href;
 	$q =~ s/%20/+/g; # improve URL readability
 	my $qs = "q=$q";
 
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 4fc8ffc..829806d 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -768,8 +768,8 @@ sub _inline_header {
 	my $mid = mid_clean($mime->header('Message-ID'));
 	my $f = $mime->header('X-PI-From');
 	my $d = _msg_date($mime);
-	$f = PublicInbox::Hval->new($f)->as_html;
-	$d = PublicInbox::Hval->new($d)->as_html;
+	$f = PublicInbox::Hval->new_oneline($f)->as_html;
+	$d = PublicInbox::Hval->new_oneline($d)->as_html;
 	my $pfx = ' ' . $d . ' ' . indent_for($level);
 	my $attr = $f;
 	$state->{first_level} ||= $level;
@@ -902,7 +902,7 @@ sub dump_topics {
 		my ($level, $subj, $topic) = @$info;
 		my $n = delete $subjs->{$topic};
 		my ($mid, $ts) = @{delete $latest->{$topic}};
-		$mid = PublicInbox::Hval->new($mid)->as_href;
+		$mid = PublicInbox::Hval->new_msgid($mid)->as_href;
 		$subj = PublicInbox::Hval->new($subj)->as_html;
 		$pfx = indent_for($level);
 		my $nl = $level == $prev ? "\n" : '';
-- 
EW


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] hval: new should not strip leading spaces
  2016-01-09  9:45 [PATCH 0/3] a few minor small fixes Eric Wong
  2016-01-09  9:45 ` [PATCH 1/3] hval: use more appropriate hvals for documentation Eric Wong
@ 2016-01-09  9:45 ` Eric Wong
  2016-01-09  9:45 ` [PATCH 3/3] view: fix Atom feed link in full message view page Eric Wong
  2016-01-09 10:55 ` [PATCH 4/3] www: fix redirection loops Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2016-01-09  9:45 UTC (permalink / raw)
  To: meta

We should be able to use this for ASCII art and paragraphs
---
 lib/PublicInbox/Hval.pm | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm
index 5a86935..d295f5c 100644
--- a/lib/PublicInbox/Hval.pm
+++ b/lib/PublicInbox/Hval.pm
@@ -21,8 +21,7 @@ my $enc_ascii = find_encoding('us-ascii');
 sub new {
 	my ($class, $raw, $href) = @_;
 
-	# we never care about leading/trailing whitespace
-	$raw =~ s/\A\s*//;
+	# we never care about trailing whitespace
 	$raw =~ s/\s*\z//;
 	bless {
 		raw => $raw,
-- 
EW


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] view: fix Atom feed link in full message view page
  2016-01-09  9:45 [PATCH 0/3] a few minor small fixes Eric Wong
  2016-01-09  9:45 ` [PATCH 1/3] hval: use more appropriate hvals for documentation Eric Wong
  2016-01-09  9:45 ` [PATCH 2/3] hval: new should not strip leading spaces Eric Wong
@ 2016-01-09  9:45 ` Eric Wong
  2016-01-09 10:55 ` [PATCH 4/3] www: fix redirection loops Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2016-01-09  9:45 UTC (permalink / raw)
  To: meta

Oops :x
---
 lib/PublicInbox/View.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 829806d..0783a1d 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -558,10 +558,11 @@ sub html_footer {
 
 	my $srch = $ctx->{srch} if $ctx;
 	my $upfx = $full_pfx ? '../' : '../../';
+	my $tpfx = $full_pfx ? '' : '../';
 	my $idx = $standalone ? " <a\nhref=\"$upfx\">index</a>" : '';
 
 	if ($srch && $standalone) {
-		$idx .= qq{ / follow: <a\nhref="t.atom">Atom feed</a>\n};
+		$idx .= qq{ / follow: <a\nhref="${tpfx}t.atom">Atom feed</a>\n};
 	}
 	if ($idx && $srch) {
 		my $p = $ctx->{parent_msg};
@@ -579,7 +580,6 @@ sub html_footer {
 			$irt .= ' ' x length('next ');
 		}
 		if ($p || $next) {
-			my $tpfx = $full_pfx ? '' : '../';
 			$irt .= "<a\nhref=\"${tpfx}t/#u\">thread</a> ";
 		} else {
 			$irt .= ' ' x length('thread ');
-- 
EW


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/3] www: fix redirection loops
  2016-01-09  9:45 [PATCH 0/3] a few minor small fixes Eric Wong
                   ` (2 preceding siblings ...)
  2016-01-09  9:45 ` [PATCH 3/3] view: fix Atom feed link in full message view page Eric Wong
@ 2016-01-09 10:55 ` Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2016-01-09 10:55 UTC (permalink / raw)
  To: meta

Sometimes users forget trailing slashes; but we should not punish
them with infinite loops.
---
 lib/PublicInbox/WWW.pm |  4 +++-
 t/plack.t              | 25 ++++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 411db16..d5635d8 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -47,7 +47,9 @@ sub run {
 
 	# in case people leave off the trailing slash:
 	} elsif ($path_info =~ m!$LISTNAME_RE/$MID_RE/(f|T|t)\z!o) {
-		r301($ctx, $1, $2, $3 eq 't' ? 't/#u' : $3);
+		my ($listname, $mid, $suffix) = ($1, $2, $3);
+		$suffix .= $suffix =~ /\A[tT]\z/ ? '/#u' : '/';
+		r301($ctx, $listname, $mid, $suffix);
 
 	# convenience redirects order matters
 	} elsif ($path_info =~ m!$LISTNAME_RE/([^/]{2,})\z!o) {
diff --git a/t/plack.t b/t/plack.t
index f61b3be..b77cdba 100644
--- a/t/plack.t
+++ b/t/plack.t
@@ -81,6 +81,30 @@ EOF
 		is($to, $res->header('Location'), 'redirect location matches');
 	});
 
+	my $pfx = 'http://example.com/test';
+	foreach my $t (qw(t T)) {
+		test_psgi($app, sub {
+			my ($cb) = @_;
+			my $u = $pfx . "/blah%40example.com/$t";
+			my $res = $cb->(GET($u));
+			is(301, $res->code, "redirect for missing /");
+			my $location = $res->header('Location');
+			like($location, qr!/\Q$t\E/#u\z!,
+				'redirected with missing /');
+		});
+	}
+	foreach my $t (qw(f)) {
+		test_psgi($app, sub {
+			my ($cb) = @_;
+			my $u = $pfx . "/blah%40example.com/$t";
+			my $res = $cb->(GET($u));
+			is(301, $res->code, "redirect for missing /");
+			my $location = $res->header('Location');
+			like($location, qr!/\Q$t\E/\z!,
+				'redirected with missing /');
+		});
+	}
+
 	test_psgi($app, sub {
 		my ($cb) = @_;
 		my $atomurl = 'http://example.com/test/new.atom';
@@ -92,7 +116,6 @@ EOF
 			'index generated');
 	});
 
-	my $pfx = 'http://example.com/test';
 	test_psgi($app, sub {
 		my ($cb) = @_;
 		my $res = $cb->(GET($pfx . '/atom.xml'));
-- 
EW


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-01-09 10:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-09  9:45 [PATCH 0/3] a few minor small fixes Eric Wong
2016-01-09  9:45 ` [PATCH 1/3] hval: use more appropriate hvals for documentation Eric Wong
2016-01-09  9:45 ` [PATCH 2/3] hval: new should not strip leading spaces Eric Wong
2016-01-09  9:45 ` [PATCH 3/3] view: fix Atom feed link in full message view page Eric Wong
2016-01-09 10:55 ` [PATCH 4/3] www: fix redirection loops Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).