Topics are (inconsistently) converted to lower-case #2469

Closed
opened 2025-11-02 04:37:24 -06:00 by GiteaMirror · 12 comments
Owner

Originally created by @michael-brade on GitHub (Oct 29, 2018).

  • Gitea version (or commit ref): 1.6.0-rc.1
  • Operating system: Debian unstable
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite

Description

A stream of inconsistencies regarding case-sensitivity of topics:

  • open a repository, select "Manage Topics", type "API", press Enter.
  • the topic is now converted to a lowercase "api" in a green box.
  • now click the "Done" button and watch the green box: it shows "API" again!
  • However, don't get your hopes up too soon: reload the current page (F5) and voila: it shows "api" again.

What I would expect: keep the topic as it is, don't lowercase or uppercase it.

Originally created by @michael-brade on GitHub (Oct 29, 2018). - Gitea version (or commit ref): 1.6.0-rc.1 - Operating system: Debian unstable - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [ ] MSSQL - [x] SQLite ## Description A stream of inconsistencies regarding case-sensitivity of topics: * open a repository, select "Manage Topics", type "**API**", press Enter. * the topic is now converted to a lowercase "**api**" in a green box. * now click the "Done" button and watch the green box: it shows "**API**" again! * However, don't get your hopes up too soon: reload the current page (F5) and voila: it shows "**api**" again. What I would expect: keep the topic as it is, don't lowercase or uppercase it.
GiteaMirror added the issue/confirmedtype/bug labels 2025-11-02 04:37:24 -06:00
Author
Owner

@lafriks commented on GitHub (Oct 30, 2018):

It is intentionally converted to lowercase to not have problems later and also have compatibility with GitHub (it also lowercases topics)

@lafriks commented on GitHub (Oct 30, 2018): It is intentionally converted to lowercase to not have problems later and also have compatibility with GitHub (it also lowercases topics)
Author
Owner

@michael-brade commented on GitHub (Oct 30, 2018):

See here: https://github.com/go-gitea/gitea/issues/5171#issuecomment-432888248 and here: https://blog.gitea.io/2018/08/gitea-1.5.0-is-released/

I don't agree with "not have problems later", it is easy enough to do case-insensitive comparisons; and I don't mind being different from GitHub where it is possible to do it better than GitHub 😃 (better in this case: the user has the freedom to decide)

@michael-brade commented on GitHub (Oct 30, 2018): See here: https://github.com/go-gitea/gitea/issues/5171#issuecomment-432888248 and here: https://blog.gitea.io/2018/08/gitea-1.5.0-is-released/ I don't agree with "not have problems later", it is easy enough to do case-insensitive comparisons; and I don't mind being different from GitHub where it is possible to do it better than GitHub :smiley: (better in this case: the user has the freedom to decide)
Author
Owner

@lafriks commented on GitHub (Oct 30, 2018):

@michael-brade but than there still be problem anyway as most probably someone will decide in your place. Let's say someone in other org/repo will add topic ApI and even if you will try to add api or API it will still be converted to ApI as topics are global to whole server. I agree that there is a bug that it jumps to lowercase, than back to uppercase and than again lowercase but otherwise I think lowecase should be enforced on this.

@lafriks commented on GitHub (Oct 30, 2018): @michael-brade but than there still be problem anyway as most probably someone will decide in your place. Let's say someone in other org/repo will add topic `ApI` and even if you will try to add `api` or `API` it will still be converted to `ApI` as topics are global to whole server. I agree that there is a bug that it jumps to lowercase, than back to uppercase and than again lowercase but otherwise I think lowecase should be enforced on this.
Author
Owner

@michael-brade commented on GitHub (Oct 30, 2018):

@lafriks oh! you're right, I didn't think about that... so then what about this: no conversion at all, and case-sensitive comparisons. Then everyone can do whatever they want, since API != Api. One might think that this clutters up the dropdowns, but that is a problem already present, so no real issue.

(The other possibility would be to have topics local to each organization or user, but I don't think it would have any advantage over other solutions and might really lead to trouble 😄)

@michael-brade commented on GitHub (Oct 30, 2018): @lafriks oh! you're right, I didn't think about that... so then what about this: no conversion at all, and case-sensitive comparisons. Then everyone can do whatever they want, since `API != Api`. One might think that this clutters up the dropdowns, but that is a problem already present, so no real issue. (The other possibility would be to have topics local to each organization or user, but I don't think it would have any advantage over other solutions and might *really* lead to trouble :smile:)
Author
Owner

@lafriks commented on GitHub (Oct 30, 2018):

I don't think that problem is currently present, in database all topics are currently already lowercase so it is only UI bug that needs to be fixed

@lafriks commented on GitHub (Oct 30, 2018): I don't think that problem is currently present, in database all topics are currently already lowercase so it is only UI bug that needs to be fixed
Author
Owner

@michael-brade commented on GitHub (Oct 30, 2018):

I think you misunderstood this one. With clutter I meant items you don't want to see in general, with typos of all sorts you can imagine. Adding uppercase letters doesn't make this kind of clutter worse. The only solution to this would be to limit suggestions to those of the current user/org, but I don't think this would be easy.

BTW: is it possible to delete a topic from the database by removing the last usage of it?

@michael-brade commented on GitHub (Oct 30, 2018): I think you misunderstood this one. With clutter I meant items you don't want to see in general, with typos of all sorts you can imagine. Adding uppercase letters doesn't make this kind of clutter worse. The only solution to this would be to limit suggestions to those of the current user/org, but I don't think this would be easy. BTW: is it possible to delete a topic from the database by removing the last usage of it?
Author
Owner

@lafriks commented on GitHub (Oct 30, 2018):

I don't think topics are deleted when not used any more currently. As for being case insensitive I'm against it as it will add clutter and will render them less useful. Especially taking into account if used in future in federation when we get to that.

@lafriks commented on GitHub (Oct 30, 2018): I don't think topics are deleted when not used any more currently. As for being case insensitive I'm against it as it will add clutter and will render them less useful. Especially taking into account if used in future in federation when we get to that.
Author
Owner

@lunny commented on GitHub (Oct 31, 2018):

Maybe we should add a whitelist to convert api to API and etc.

@lunny commented on GitHub (Oct 31, 2018): Maybe we should add a whitelist to convert `api` to `API` and etc.
Author
Owner

@lafriks commented on GitHub (Oct 31, 2018):

IMHO that is not needed as that will still not cover all

@lafriks commented on GitHub (Oct 31, 2018): IMHO that is not needed as that will still not cover all
Author
Owner

@michael-brade commented on GitHub (Nov 1, 2018):

Ok, I changed it for my own server to case-sensitive. And I have to say, gitea is really good code! It is very easy to find my way around in it and to understand what's going on. Lovely. If anyone is interested, here is the patch that makes Topics case-sensitive:

diff --git a/models/topic.go b/models/topic.go
index 678795a3d..69071a39b 100644
--- a/models/topic.go
+++ b/models/topic.go
@@ -21,7 +21,7 @@ func init() {
        )
 }
 
-var topicPattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-]*$`)
+var topicPattern = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9-]*$`)
 
 // Topic represents a topic of repositories
 type Topic struct {
@@ -127,7 +127,7 @@ func SaveTopics(repoID int64, topicNames ...string) error {
 
                var found bool
                for _, t := range topics {
-                       if strings.EqualFold(topicName, t.Name) {
+                       if topicName == t.Name {
                                found = true
                                break
                        }
@@ -141,7 +141,7 @@ func SaveTopics(repoID int64, topicNames ...string) error {
        for _, t := range topics {
                var found bool
                for _, topicName := range topicNames {
-                       if strings.EqualFold(topicName, t.Name) {
+                       if topicName == t.Name {
                                found = true
                                break
                        }
diff --git a/public/js/index.js b/public/js/index.js
index 0bc28c4f9..5351d4040 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -2523,12 +2523,12 @@ function initTopicbar() {
             },
         },
         onLabelCreate: function(value) {
-            value = value.toLowerCase().trim();
+            value = value.trim();
             this.attr("data-value", value).contents().first().replaceWith(value);
             return $(this);
         },
         onAdd: function(addedValue, addedText, $addedChoice) {
-            addedValue = addedValue.toLowerCase().trim();
+            addedValue = addedValue.trim();
             $($addedChoice).attr('data-value', addedValue);
             $($addedChoice).attr('data-text', addedValue);
         }
@@ -2553,7 +2553,7 @@ function initTopicbar() {
                     rules: [
                         {
                             type: 'validateTopic',
-                            value: /^[a-z0-9][a-z0-9-]{1,35}$/,
+                            value: /^[A-Za-z0-9][A-Za-z0-9-]{1,35}$/,
                             prompt: topicPrompts.formatPrompt
                         },
                         {
diff --git a/routers/repo/topic.go b/routers/repo/topic.go
index 63fcf793f..3fa1205e7 100644
--- a/routers/repo/topic.go
+++ b/routers/repo/topic.go
@@ -30,7 +30,7 @@ func TopicsPost(ctx *context.Context) {
        invalidTopics := make([]string, 0)
        i := 0
        for _, topic := range topics {
-               topic = strings.TrimSpace(strings.ToLower(topic))
+               topic = strings.TrimSpace(topic)
                // ignore empty string
                if len(topic) > 0 {
                        topics[i] = topic
@michael-brade commented on GitHub (Nov 1, 2018): Ok, I changed it for my own server to case-sensitive. And I have to say, gitea is really good code! It is very easy to find my way around in it and to understand what's going on. Lovely. If anyone is interested, here is the patch that makes Topics case-sensitive: ```go diff --git a/models/topic.go b/models/topic.go index 678795a3d..69071a39b 100644 --- a/models/topic.go +++ b/models/topic.go @@ -21,7 +21,7 @@ func init() { ) } -var topicPattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-]*$`) +var topicPattern = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9-]*$`) // Topic represents a topic of repositories type Topic struct { @@ -127,7 +127,7 @@ func SaveTopics(repoID int64, topicNames ...string) error { var found bool for _, t := range topics { - if strings.EqualFold(topicName, t.Name) { + if topicName == t.Name { found = true break } @@ -141,7 +141,7 @@ func SaveTopics(repoID int64, topicNames ...string) error { for _, t := range topics { var found bool for _, topicName := range topicNames { - if strings.EqualFold(topicName, t.Name) { + if topicName == t.Name { found = true break } diff --git a/public/js/index.js b/public/js/index.js index 0bc28c4f9..5351d4040 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2523,12 +2523,12 @@ function initTopicbar() { }, }, onLabelCreate: function(value) { - value = value.toLowerCase().trim(); + value = value.trim(); this.attr("data-value", value).contents().first().replaceWith(value); return $(this); }, onAdd: function(addedValue, addedText, $addedChoice) { - addedValue = addedValue.toLowerCase().trim(); + addedValue = addedValue.trim(); $($addedChoice).attr('data-value', addedValue); $($addedChoice).attr('data-text', addedValue); } @@ -2553,7 +2553,7 @@ function initTopicbar() { rules: [ { type: 'validateTopic', - value: /^[a-z0-9][a-z0-9-]{1,35}$/, + value: /^[A-Za-z0-9][A-Za-z0-9-]{1,35}$/, prompt: topicPrompts.formatPrompt }, { diff --git a/routers/repo/topic.go b/routers/repo/topic.go index 63fcf793f..3fa1205e7 100644 --- a/routers/repo/topic.go +++ b/routers/repo/topic.go @@ -30,7 +30,7 @@ func TopicsPost(ctx *context.Context) { invalidTopics := make([]string, 0) i := 0 for _, topic := range topics { - topic = strings.TrimSpace(strings.ToLower(topic)) + topic = strings.TrimSpace(topic) // ignore empty string if len(topic) > 0 { topics[i] = topic ```
Author
Owner

@stale[bot] commented on GitHub (Jan 5, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (Jan 5, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
Author
Owner

@stale[bot] commented on GitHub (Feb 23, 2019):

This issue has been automatically closed because of inactivity. You can re-open it if needed.

@stale[bot] commented on GitHub (Feb 23, 2019): This issue has been automatically closed because of inactivity. You can re-open it if needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#2469